Kernel#instance_eval should define singleton methods; fix #4069

parent cb42c987
......@@ -325,6 +325,7 @@ f_instance_eval(mrb_state *mrb, mrb_value self)
proc = create_proc_from_string(mrb, s, len, mrb_nil_value(), file, line);
MRB_PROC_SET_TARGET_CLASS(proc, mrb_class_ptr(cv));
mrb_assert(!MRB_PROC_CFUNC_P(proc));
mrb->c->ci->target_class = mrb_class_ptr(cv);
return exec_irep(mrb, self, proc);
}
else {
......
......@@ -100,7 +100,22 @@ assert('Object#instance_eval with begin-rescue-ensure execution order') do
assert_equal([:enter_raise_hell, :begin, :rescue, :ensure], hell_raiser.raise_hell)
end
assert('Kernel.#eval(strinng) Issue #4021') do
assert('Kernel#instance_eval() to define singleton methods Issue #3141') do
foo_class = Class.new do
def bar(x)
instance_eval "def baz; #{x}; end"
end
end
f1 = foo_class.new
f2 = foo_class.new
f1.bar 1
f2.bar 2
assert_equal(1){f1.baz}
assert_equal(2){f2.baz}
end
assert('Kernel.#eval(string) Issue #4021') do
assert_equal('FOO') { (eval <<'EOS').call }
foo = "FOO"
Proc.new { foo }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment