aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-01 07:50:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-01 07:50:53 +0000
commitdc460944bb483b45908ab028fa64467113a45ddc (patch)
treea52f0e7e2806d023f52a05d7e35032dc04eed1b2 /object.c
parent430d3bd6e0cc4a2fd0616c1a2a11e371248d0737 (diff)
downloadruby-dc460944bb483b45908ab028fa64467113a45ddc.tar.gz
object.c: Kernel#yield_self
* object.c (rb_obj_yield_self): new method which yields the receiver and returns the result. [ruby-core:46320] [Feature #6721] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/object.c b/object.c
index 92cea14514..184a72f1fa 100644
--- a/object.c
+++ b/object.c
@@ -497,6 +497,23 @@ rb_obj_itself(VALUE obj)
return obj;
}
+/*
+ * call-seq:
+ * obj.yield_self {|_obj|...} -> an_object
+ *
+ * Yields <i>obj</i> and returns the result.
+ *
+ * 'my string'.yield_self {|s|s.upcase} #=> "MY STRING"
+ *
+ */
+
+static VALUE
+rb_obj_yield_self(VALUE obj)
+{
+ RETURN_ENUMERATOR(obj, 0, 0);
+ return rb_yield_values2(1, &obj);
+}
+
/* :nodoc: */
VALUE
rb_obj_init_copy(VALUE obj, VALUE orig)
@@ -3507,6 +3524,7 @@ InitVM_Object(void)
rb_define_method(rb_mKernel, "clone", rb_obj_clone2, -1);
rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
rb_define_method(rb_mKernel, "itself", rb_obj_itself, 0);
+ rb_define_method(rb_mKernel, "yield_self", rb_obj_yield_self, 0);
rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
rb_define_method(rb_mKernel, "initialize_dup", rb_obj_init_dup_clone, 1);
rb_define_method(rb_mKernel, "initialize_clone", rb_obj_init_dup_clone, 1);