struct RClass* mrb_define_module_id(mrb_state *mrb, mrb_sym name) { struct RClass *m = mrb_module_new(mrb); mrb_obj_iv_set(mrb, (struct RObject*)mrb->object_class, name, mrb_obj_value(m)); mrb_name_class(mrb, m, name); return m; }
struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name) { struct RClass * c; mrb_sym id = mrb_intern(mrb, name); if (mrb_const_defined_at(mrb, outer, id)) { c = class_from_sym(mrb, outer, id); return c; } c = mrb_module_new(mrb); setup_class(mrb, mrb_obj_value(outer), c, id); return c; }
struct RClass* mrb_vm_define_module(mrb_state *mrb, mrb_value outer, mrb_sym id) { struct RClass *c; mrb_value v; if (mrb_const_defined(mrb, outer, id)) { v = mrb_const_get(mrb, outer, id); c = mrb_class_ptr(v); } else { c = mrb_module_new(mrb); setup_class(mrb, outer, c, id); } return c; }
struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name) { struct RClass * c; mrb_sym id = mrb_intern(mrb, name); if (mrb_const_defined_at(mrb, outer, id)) { c = mrb_class_from_sym(mrb, outer, id); if (c->tt != MRB_TT_MODULE) { mrb_raise(mrb, E_TYPE_ERROR, "%s is not a module", mrb_sym2name(mrb, id)); } return c; } c = mrb_module_new(mrb); setup_class(mrb, mrb_obj_value(outer), c, id); mrb_const_set(mrb, mrb_obj_value(outer), id, mrb_obj_value(c)); return c; }