Skip to content

Commit

Permalink
Should call initialize method if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Dec 22, 2016
1 parent 3cba13c commit a68b568
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static mrb_value
mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class)
{
mrb_value blk;
mrb_value proc;
struct RProc *p;

mrb_get_args(mrb, "&", &blk);
Expand All @@ -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));
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
Expand Down
12 changes: 12 additions & 0 deletions test/t/proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ def return_nil
assert_equal c, c.block.call
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
pr = Proc.new{}
def mock(&b)
Expand Down

0 comments on commit a68b568

Please sign in to comment.