ruby-changes:4680
From: ko1@a...
Date: Wed, 23 Apr 2008 15:45:15 +0900 (JST)
Subject: [ruby-changes:4680] knu - Ruby:r16174 (ruby_1_8): * eval.c (bind_eval): Add Binding#eval, a shorthand method for
knu 2008-04-23 15:44:56 +0900 (Wed, 23 Apr 2008)
New Revision: 16174
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/NEWS
branches/ruby_1_8/eval.c
Log:
* eval.c (bind_eval): Add Binding#eval, a shorthand method for
eval(str, binding, ..); backported from 1.9.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16174&r2=16173&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=16174&r2=16173&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/eval.c?r1=16174&r2=16173&diff_format=u
Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS (revision 16173)
+++ ruby_1_8/NEWS (revision 16174)
@@ -73,6 +73,10 @@
New methods.
+ * Binding#eval
+
+ New method.
+
* Dir#each
* Dir#foreach
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16173)
+++ ruby_1_8/ChangeLog (revision 16174)
@@ -1,3 +1,8 @@
+Wed Apr 23 15:39:31 2008 Akinori MUSHA <knu@i...>
+
+ * 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@m...>
* test/gdbm/test_gdbm.rb (TestGDBM#test_s_open_no_create): failed
Index: ruby_1_8/eval.c
===================================================================
--- ruby_1_8/eval.c (revision 16173)
+++ ruby_1_8/eval.c (revision 16174)
@@ -8471,6 +8471,35 @@
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 @@
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);
}
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/