Skip to content

Commit

Permalink
raise a RuntimeError if the method is defined by `define_method' with…
Browse files Browse the repository at this point in the history
… frozen class
  • Loading branch information
Watson1978 committed Jun 24, 2012
1 parent 43448df commit ff1e365
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ fails:Module#define_method passed { |a, *b| } creates a method that raises an A
fails:Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed zero arguments
fails:Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument
fails:Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument and a block
fails:Module#define_method raises a RuntimeError if frozen
4 changes: 4 additions & 0 deletions vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,10 @@ __rb_vm_define_method(Class klass, SEL sel, IMP objc_imp, IMP ruby_imp,
return NULL;
}

if (OBJ_FROZEN(klass)) {
rb_error_frozen("class/module");
}

const char *sel_name = sel_getName(sel);
const bool genuine_selector = sel_name[strlen(sel_name) - 1] == ':';
int types_count = genuine_selector ? arity.real + 3 : 3;
Expand Down

0 comments on commit ff1e365

Please sign in to comment.