Introduction

Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable. This class embeds the Ruby interpreter in a C++ application.

Usage examples

  RubyEval& ruby = *RubyEval::instance();

  ruby.eval("puts 'hello ruby'");

  assert( NUM2INT( ruby.eval("1+1") ) == 2 );

  assert(RubyEval::val2str(ruby.eval("'Regexp'.gsub(/x/, 'X')")) == "RegeXp");

Download

Class documentation

Public Methods

 

~RubyEval ()

void 

run_file (const char *filename, ostream &out=cout)

 

Run Ruby interpreter with filename. ****

VALUE 

eval (const char *code)

 

Evaluate code string. ****

VALUE 

eval (const char *code, ostream &errout)

 

Evaluate code string and print errors. ****

bool 

evalOk ()

 

Last evaluation was successful. ****

Static Public Methods

RubyEval * 

instance ()

 

Singleton Instance. ****

string 

val2str (const VALUE rval)

 

Convert Ruby value to string. ****

string 

strval2str (const VALUE rval)

 

Convert Ruby string value to string. ****

void 

exception_print (ostream &errout=cerr)

 

Get Ruby error/exception info an print it. ****

string 

exception_info ()

 

Get Ruby error/exception info as string. ****