summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-02 01:26:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-02 01:26:58 +0000
commit0a0160d6b659f6131a525fe1579e7c463d4c197e (patch)
tree75a47d4daf59eb71d11e4209a2fdd1cc718a1870
parenta13944dc1cce2106e5267046c788e680a8cdefa4 (diff)
object.c: Object#itsef
* 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
-rw-r--r--ChangeLog7
-rw-r--r--NEWS4
-rw-r--r--object.c18
-rw-r--r--test/ruby/test_object.rb6
4 files changed, 35 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index fdda286..0ebe70c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Aug 2 10:26:57 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * object.c (rb_obj_itself): new method Object#itsef. based on the
+ patch by Rafael Franca in [ruby-core:64156].
+ [EXPERIMENTAL] this method may be renamed due to compatibilities.
+ [ruby-core:44704] [Feature #6373]
+
Fri Aug 1 22:30:40 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (folerecord_inititalize): accept
diff --git a/NEWS b/NEWS
index 9485a99..84108b9 100644
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,10 @@ with all sufficient information, see the ChangeLog file.
* New methods:
* File::Stat#birthtime
+* Kernel
+ * New methods:
+ * Kernel#itself
+
* Process
* Extended method:
* Process execution methods such as Process.spawn opens the file in write
diff --git a/object.c b/object.c
index 21772de..b994539 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 <i>obj</i>.
+ *
+ * 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);
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index f305cc7..4573dc8 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -12,6 +12,12 @@ class TestObject < Test::Unit::TestCase
$VERBOSE = @verbose
end
+ def test_itself
+ feature6373 = '[ruby-core:44704] [Feature #6373]'
+ object = Object.new
+ assert_same(object, object.itself, feature6373)
+ end
+
def test_dup
assert_raise(TypeError) { 1.dup }
assert_raise(TypeError) { true.dup }