summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-23 09:38:54 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-23 09:38:54 +0000
commita3e10f380ab276cc9192418d2a19c7e0ffc86046 (patch)
tree8e8606530db6687e552767ccf6299e17d8e4a164 /object.c
parent094d03c5d3bbbd9a68ff4f0d86bd988e29773da1 (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/trunk@27022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/object.c b/object.c
index f473fe1e4f..939d5edc6d 100644
--- a/object.c
+++ b/object.c
@@ -162,6 +162,29 @@ rb_obj_class(VALUE 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(VALUE obj)
+{
+ return rb_singleton_class(obj);
+}
+
static void
init_copy(VALUE dest, VALUE obj)
{
@@ -2585,6 +2608,7 @@ Init_Object(void)
rb_define_method(rb_mKernel, "<=>", rb_obj_cmp, 1);
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);
rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);