diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-05-08 23:25:13 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-05-08 23:25:13 +0900 |
| commit | 8a6d4a8b82fdcca70a16b6c837e7177e5fe6b90f (patch) | |
| tree | 9d60cb196f2c89b1d334fb0cfb189421b532cf27 /src/class.c | |
| parent | aac2c1c1a62bd1bcad9900b0bf8ddf65e4ace206 (diff) | |
| download | mruby-8a6d4a8b82fdcca70a16b6c837e7177e5fe6b90f.tar.gz mruby-8a6d4a8b82fdcca70a16b6c837e7177e5fe6b90f.zip | |
add Class#inherited hook
Diffstat (limited to 'src/class.c')
| -rw-r--r-- | src/class.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/class.c b/src/class.c index 34ffd2fa8..f366d4d1f 100644 --- a/src/class.c +++ b/src/class.c @@ -217,8 +217,12 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id mrb_check_type(mrb, super, MRB_TT_CLASS); s = mrb_class_ptr(super); } + if (!s) { + s = mrb->object_class; + } c = mrb_class_new(mrb, s); setup_class(mrb, outer, c, id); + mrb_funcall(mrb, mrb_obj_value(s), "inherited", 1, mrb_obj_value(c)); } return c; @@ -1075,6 +1079,7 @@ mrb_init_class(mrb_state *mrb) mrb_define_method(mrb, bob, "!", mrb_bob_not, ARGS_NONE()); mrb_define_method(mrb, bob, "method_missing", mrb_bob_missing, ARGS_ANY()); /* 15.3.1.3.30 */ mrb_define_method(mrb, cls, "new", mrb_instance_new, ARGS_ANY()); + mrb_define_method(mrb, cls, "inherited", mrb_bob_init, ARGS_REQ(1)); mrb_define_method(mrb, mod, "include", mrb_mod_include, ARGS_REQ(1)); mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE()); |
