diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-22 12:42:57 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-22 12:42:57 +0000 |
| commit | a2b186bee4d4a8aec91cfd46b135f3448f731c54 (patch) | |
| tree | 47500471349bff02a59339d19d7b846572aef0e8 /object.c | |
| parent | 185e2676afec07e07dc2cbe09db0c8a1965b50af (diff) | |
* eval.c (rb_proc_new): Turn the BLOCK_LAMBDA flag on.
* object.c (sym_to_proc), test/ruby/test_symbol.rb: Add back
Symbol#to_proc, now that it passes the tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
| -rw-r--r-- | object.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -1212,6 +1212,35 @@ sym_to_sym(sym) } +static VALUE +sym_call(args, mid) + VALUE args, mid; +{ + VALUE obj; + + if (RARRAY(args)->len < 1) { + rb_raise(rb_eArgError, "no receiver given"); + } + obj = rb_ary_shift(args); + return rb_apply(obj, (ID)mid, args); +} + +/* + * call-seq: + * sym.to_proc + * + * Returns a _Proc_ object which respond to the given method by _sym_. + * + * (1..3).collect(&:to_s) #=> ["1", "2", "3"] + */ + +static VALUE +sym_to_proc(VALUE sym) +{ + return rb_proc_new(sym_call, (VALUE)SYM2ID(sym)); +} + + /*********************************************************************** * * Document-class: Module @@ -2755,6 +2784,7 @@ Init_Object() rb_define_method(rb_cSymbol, "to_s", sym_to_s, 0); rb_define_method(rb_cSymbol, "id2name", sym_to_s, 0); rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0); + rb_define_method(rb_cSymbol, "to_proc", sym_to_proc, 0); rb_define_method(rb_cSymbol, "===", rb_obj_equal, 1); rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0); |
