aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-08 14:01:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-08 14:01:23 +0000
commita25d02b144c9560dc3d1139a4a0024b6ade6e21c (patch)
treea2e6a46c6901e03492632131817c30402dab124b /object.c
parent44aa21d4aa25c036e1a6178c596f48cd1de9f254 (diff)
downloadruby-a25d02b144c9560dc3d1139a4a0024b6ade6e21c.tar.gz
object.c: Module#singleton_class?
* object.c (rb_mod_singleton_p): new method Module#singleton_class? to return whether the receiver is a singleton class or not. [ruby-core:51087] [Feature #7609] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/object.c b/object.c
index 3bcad9fea7..965c83cb84 100644
--- a/object.c
+++ b/object.c
@@ -2385,6 +2385,14 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv)
return rb_cvar_defined(obj, id);
}
+static VALUE
+rb_mod_singleton_p(VALUE klass)
+{
+ if (RB_TYPE_P(klass, T_CLASS) && FL_TEST(klass, FL_SINGLETON))
+ return Qtrue;
+ return Qfalse;
+}
+
static struct conv_method_tbl {
const char *method;
ID id;
@@ -3225,6 +3233,7 @@ Init_Object(void)
rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
rb_define_method(rb_cModule, "public_constant", rb_mod_public_constant, -1); /* in variable.c */
rb_define_method(rb_cModule, "private_constant", rb_mod_private_constant, -1); /* in variable.c */
+ rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0);
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);