From cb4d196df165d746291ce0edd5aa377f00b2554d Mon Sep 17 00:00:00 2001 From: knu Date: Thu, 25 Mar 2010 18:09:57 +0000 Subject: * 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 --- object.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'object.c') diff --git a/object.c b/object.c index b34a57195a..976b94760a 100644 --- a/object.c +++ b/object.c @@ -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 obj. This method creates + * a new singleton class if obj does not have it. + * + * If obj is nil, true, or + * false, it returns NilClass, TrueClass, or FalseClass, + * respectively. + * If obj is a Fixnum or a Symbol, it raises a TypeError. + * + * Object.new.singleton_class #=> #> + * String.singleton_class #=> # + * 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); -- cgit v1.2.3