Merge pull request #3746 from christopheraue/mod_singleton_class_p

Implemented Module#singleton_class?
This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-07-19 09:08:11 +09:00
committed by GitHub
2 changed files with 17 additions and 0 deletions
+7
View File
@@ -9,12 +9,19 @@ mrb_mod_name(mrb_state *mrb, mrb_value self)
return mrb_nil_p(name)? name : mrb_str_dup(mrb, name);
}
static mrb_value
mrb_mod_singleton_class_p(mrb_state *mrb, mrb_value self)
{
return mrb_bool_value(mrb_type(self) == MRB_TT_SCLASS);
}
void
mrb_mruby_class_ext_gem_init(mrb_state *mrb)
{
struct RClass *mod = mrb->module_class;
mrb_define_method(mrb, mod, "name", mrb_mod_name, MRB_ARGS_NONE());
mrb_define_method(mrb, mod, "singleton_class?", mrb_mod_singleton_class_p, MRB_ARGS_NONE());
}
void
+10
View File
@@ -22,3 +22,13 @@ assert 'Module#name' do
assert_nil mod.name
assert_nil cls.name
end
assert 'Module#singleton_class?' do
mod = Module.new
cls = Class.new
scl = cls.singleton_class
assert_false mod.singleton_class?
assert_false cls.singleton_class?
assert_true scl.singleton_class?
end