From 0a0160d6b659f6131a525fe1579e7c463d4c197e Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 2 Aug 2014 01:26:58 +0000 Subject: object.c: Object#itsef MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * object.c (rb_obj_itself): new method Object#itsef. based on the patch by Rafael França in [ruby-core:64156]. [EXPERIMENTAL] this method may be renamed due to compatibilities. [ruby-core:44704] [Feature #6373] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'object.c') diff --git a/object.c b/object.c index 21772deb56..b994539350 100644 --- a/object.c +++ b/object.c @@ -402,6 +402,23 @@ rb_obj_dup(VALUE obj) return dup; } +/* + * call-seq: + * obj.itself -> an_object + * + * Returns obj. + * + * string = 'my string' #=> "my string" + * string.itself.object_id == string.object_id #=> true + * + */ + +static VALUE +rb_obj_itself(VALUE obj) +{ + return obj; +} + /* :nodoc: */ VALUE rb_obj_init_copy(VALUE obj, VALUE orig) @@ -3302,6 +3319,7 @@ Init_Object(void) rb_define_method(rb_mKernel, "singleton_class", rb_obj_singleton_class, 0); rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0); 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, "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); -- cgit v1.2.3