summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-10 19:38:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-10 19:38:45 +0000
commitac4d6ddfa3219c212d2865ed600a0ab568d5f0b5 (patch)
tree801a8837eda59222c1848f7eaa204be8c646f37a /object.c
parent36d0a4eab0ffaac6891c361ac3fab3d13bce777c (diff)
* object.c (sym_to_proc): imported Symbol#to_proc from ActiveSupprot.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/object.c b/object.c
index 6481ce5880..f1d87c022a 100644
--- a/object.c
+++ b/object.c
@@ -1055,6 +1055,31 @@ sym_to_sym(VALUE sym)
return sym;
}
+static VALUE
+sym_call(VALUE args, VALUE sym)
+{
+ VALUE obj = RARRAY(args)->ptr[0];
+
+ return rb_funcall(obj, SYM2ID(sym),
+ RARRAY(args)->len - 1,
+ RARRAY(args)->ptr + 1);
+}
+
+/*
+ * 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, sym);
+}
+
/***********************************************************************
*
@@ -2453,7 +2478,8 @@ Init_Object(void)
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, "===", rb_obj_equal, 1);
+ 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);
rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);