Project

General

Profile

Feature #7609 ยป singleton_class_p.patch

nobu (Nobuyoshi Nakada), 12/23/2012 05:48 PM

View differences:

object.c
2273 2273
    return rb_cvar_defined(obj, id);
2274 2274
}
2275 2275

  
2276
static VALUE
2277
rb_mod_singleton_p(VALUE klass)
2278
{
2279
    if (RB_TYPE_P(klass, T_CLASS) && FL_TEST(klass, FL_SINGLETON))
2280
	return Qtrue;
2281
    return Qfalse;
2282
}
2283

  
2276 2284
static struct conv_method_tbl {
2277 2285
    const char *method;
2278 2286
    ID id;
......
3110 3118
    rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
3111 3119
    rb_define_method(rb_cModule, "public_constant", rb_mod_public_constant, -1); /* in variable.c */
3112 3120
    rb_define_method(rb_cModule, "private_constant", rb_mod_private_constant, -1); /* in variable.c */
3121
    rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0);
3113 3122

  
3114 3123
    rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
3115 3124
    rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
test/ruby/test_class.rb
336 336
      EOF
337 337
    end
338 338
  end
339

  
340
  def test_singleton_class_p
341
    assert_predicate(self.singleton_class, :singleton_class?)
342
    assert_not_predicate(self.class, :singleton_class?)
343
  end
339 344
end