diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-23 06:44:56 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-23 06:44:56 +0000 |
| commit | afc2d9e389df02619a6eee1dfe355662641ca07d (patch) | |
| tree | 318234f1543b5006cde4ea3b9f3de87eedf97d2e | |
| parent | e78826ffec9463042a6f396028d9f9fecd60e895 (diff) | |
* eval.c (bind_eval): Add Binding#eval, a shorthand method for
eval(str, binding, ..); backported from 1.9.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | eval.c | 30 |
3 files changed, 39 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Wed Apr 23 15:39:31 2008 Akinori MUSHA <knu@iDaemons.org> + + * eval.c (bind_eval): Add Binding#eval, a shorthand method for + eval(str, binding, ..); backported from 1.9. + Wed Apr 23 15:28:52 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> * test/gdbm/test_gdbm.rb (TestGDBM#test_s_open_no_create): failed @@ -73,6 +73,10 @@ with all sufficient information, see the ChangeLog file. New methods. + * Binding#eval + + New method. + * Dir#each * Dir#foreach @@ -8471,6 +8471,35 @@ rb_f_binding(self) return bind; } +/* + * call-seq: + * binding.eval(string [, filename [,lineno]]) => obj + * + * Evaluates the Ruby expression(s) in <em>string</em>, in the + * <em>binding</em>'s context. If the optional <em>filename</em> and + * <em>lineno</em> parameters are present, they will be used when + * reporting syntax errors. + * + * def getBinding(param) + * return binding + * end + * b = getBinding("hello") + * b.eval("param") #=> "hello" + */ + +static VALUE +bind_eval(argc, argv, bindval) + int argc; + VALUE *argv; + VALUE bindval; +{ + VALUE args[4]; + + rb_scan_args(argc, argv, "12", &args[0], &args[2], &args[3]); + args[1] = bindval; + return rb_f_eval(argc+1, args, Qnil /* self will be searched in eval */); +} + #define PROC_TSHIFT (FL_USHIFT+1) #define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3) #define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT) @@ -9899,6 +9928,7 @@ Init_Binding() rb_undef_method(CLASS_OF(rb_cBinding), "new"); rb_define_method(rb_cBinding, "clone", proc_clone, 0); rb_define_method(rb_cBinding, "dup", proc_dup, 0); + rb_define_method(rb_cBinding, "eval", bind_eval, -1); rb_define_global_function("binding", rb_f_binding, 0); } |
