[前][次][番号順一覧][スレッド一覧]

ruby-changes:15170

From: knu <ko1@a...>
Date: Fri, 26 Mar 2010 03:16:07 +0900 (JST)
Subject: [ruby-changes:15170] Ruby:r27049 (ruby_1_8): * object.c (rb_obj_singleton_class): new method

knu	2010-03-26 03:09:57 +0900 (Fri, 26 Mar 2010)

  New Revision: 27049

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27049

  Log:
    * object.c (rb_obj_singleton_class): new method
      Kernel#singleton_class.  [ruby-core:21702]

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/NEWS
    branches/ruby_1_8/object.c

Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS	(revision 27048)
+++ ruby_1_8/NEWS	(revision 27049)
@@ -82,6 +82,10 @@
 
     Renamed from Hash#index.
 
+  * Kernel#singleton_class
+
+    New method.
+
   * ENV.key
 
     Renamed from ENV.index.
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 27048)
+++ ruby_1_8/ChangeLog	(revision 27049)
@@ -1,3 +1,8 @@
+Fri Mar 26 03:09:30 2010  Akinori MUSHA  <knu@i...>
+
+	* object.c (rb_obj_singleton_class): new method
+	  Kernel#singleton_class.  [ruby-core:21702]
+
 Thu Mar 25 03:52:45 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/iconv/charset_alias.rb: update of URL.  [ruby-dev:38360]
Index: ruby_1_8/object.c
===================================================================
--- ruby_1_8/object.c	(revision 27048)
+++ ruby_1_8/object.c	(revision 27049)
@@ -160,6 +160,30 @@
     return rb_class_real(CLASS_OF(obj));
 }
 
+/*
+ *  call-seq:
+ *     obj.singleton_class    => class
+ *
+ *  Returns the singleton class of <i>obj</i>.  This method creates
+ *  a new singleton class if <i>obj</i> does not have it.
+ *
+ *  If <i>obj</i> is <code>nil</code>, <code>true</code>, or
+ *  <code>false</code>, it returns NilClass, TrueClass, or FalseClass,
+ *  respectively.
+ *  If <i>obj</i> is a Fixnum or a Symbol, it raises a TypeError.
+ *
+ *     Object.new.singleton_class  #=> #<Class:#<Object:0xb7ce1e24>>
+ *     String.singleton_class      #=> #<Class:String>
+ *     nil.singleton_class         #=> NilClass
+ */
+
+static VALUE
+rb_obj_singleton_class(obj)
+    VALUE obj;
+{
+    return rb_singleton_class(obj);
+}
+
 static void
 init_copy(dest, obj)
     VALUE dest, obj;
@@ -2746,6 +2770,7 @@
     rb_define_method(rb_mKernel, "id", rb_obj_id_obsolete, 0);
     rb_define_method(rb_mKernel, "type", rb_obj_type, 0);
     rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
+    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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]