diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-25 18:09:57 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-25 18:09:57 +0000 |
commit | cb4d196df165d746291ce0edd5aa377f00b2554d (patch) | |
tree | b8d88baa3daea1f4cc48dae51e3c7f88ef132678 | |
parent | bc2088b572de98f593bf4196c3f0dee9f4cc819c (diff) |
* object.c (rb_obj_singleton_class): new method
Kernel#singleton_class. [ruby-core:21702]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | object.c | 25 |
3 files changed, 34 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Fri Mar 26 03:09:30 2010 Akinori MUSHA <[email protected]> + + * object.c (rb_obj_singleton_class): new method + Kernel#singleton_class. [ruby-core:21702] + Thu Mar 25 03:52:45 2010 Nobuyoshi Nakada <[email protected]> * ext/iconv/charset_alias.rb: update of URL. [ruby-dev:38360] @@ -82,6 +82,10 @@ with all sufficient information, see the ChangeLog file. Renamed from Hash#index. + * Kernel#singleton_class + + New method. + * ENV.key Renamed from ENV.index. @@ -160,6 +160,30 @@ rb_obj_class(obj) 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 @@ Init_Object() 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); |