Unverified Commit a68b5689 authored by ksss's avatar ksss

Should call initialize method if defined

parent 3cba13c2
...@@ -151,6 +151,7 @@ static mrb_value ...@@ -151,6 +151,7 @@ static mrb_value
mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class) mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class)
{ {
mrb_value blk; mrb_value blk;
mrb_value proc;
struct RProc *p; struct RProc *p;
mrb_get_args(mrb, "&", &blk); mrb_get_args(mrb, "&", &blk);
...@@ -160,7 +161,9 @@ mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class) ...@@ -160,7 +161,9 @@ mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class)
} }
p = (struct RProc *)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb_class_ptr(proc_class)); p = (struct RProc *)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb_class_ptr(proc_class));
mrb_proc_copy(p, mrb_proc_ptr(blk)); mrb_proc_copy(p, mrb_proc_ptr(blk));
return mrb_obj_value(p); proc = mrb_obj_value(p);
mrb_funcall_with_block(mrb, proc, mrb_intern_lit(mrb, "initialize"), 0, NULL, blk);
return proc;
} }
static mrb_value static mrb_value
......
...@@ -136,6 +136,18 @@ assert('Proc#return_does_not_break_self') do ...@@ -136,6 +136,18 @@ assert('Proc#return_does_not_break_self') do
assert_equal c, c.block.call assert_equal c, c.block.call
end end
assert('call Proc#initialize if defined') do
a = []
c = Class.new(Proc) do
define_method(:initialize) do
a << :ok
end
end
assert_kind_of c, c.new{}
assert_equal [:ok], a
end
assert('&obj call to_proc if defined') do assert('&obj call to_proc if defined') do
pr = Proc.new{} pr = Proc.new{}
def mock(&b) def mock(&b)
......
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