APIdock / Ruby
/
method

eval

ruby latest stable - Class: Kernel
eval(p1, p2 = v2, p3 = v3, p4 = v4)
public

Evaluates the Ruby expression(s) in string. If binding is given, which must be a Binding object, the evaluation is performed in its context. If the optional filename and lineno parameters are present, they will be used when reporting syntax errors.

def get_binding(str)
 return binding 
end
str = "hello"
eval  "str + ' Fred'" #=> "hello Fred"
eval  "str + ' Fred'", get_binding("bye") #=> "bye Fred"
VALUE
rb_f_eval(int argc, const VALUE *argv, VALUE self)
{
 VALUE src, scope, vfile, vline;
 VALUE file = Qundef;
 int line = 1;
 rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
 SafeStringValue(src);
 if (argc >= 3) {
 StringValue(vfile);
 }
 if (argc >= 4) {
 line = NUM2INT(vline);
 }
 if (!NIL_P(vfile))
 file = vfile;
 return eval_string(self, src, scope, file, line);
}

AltStyle によって変換されたページ (->オリジナル) /