Skip to content

Commit

Permalink
freeze classes/modules; ref #3340
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Dec 11, 2016
1 parent 761562b commit 1164463
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, struct RPro
MRB_CLASS_ORIGIN(c);
h = c->mt;

if (MRB_FROZEN_P(c)) {
if (c->tt == MRB_TT_MODULE)
mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen module");
else
mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen class");
}
if (!h) h = c->mt = kh_init(mt, mrb);
k = kh_put(mt, mrb, h, mid);
kh_value(h, k) = p;
Expand Down

0 comments on commit 1164463

Please sign in to comment.