From 388d26d77027feaa3e107abf7209e2681868bbe6 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 4 Nov 2017 11:20:04 +0900 Subject: Reimplement `block_given?`; ref #3841 Make `block_given?` to search for the top of the scope first. The top of the scope means either: * the top method body * the enclosing class body * the top-level The special case is the method defined by `define_method` with a block as in #3841. In cases like this, the method body (given by a block) is not considered as the top of the scope. You need to use `&block` in the block parameter if you want to know if a block is given to the method. This commit also changes the behavior of `MRB_PROC_SCOPE` flag. Now it is only set if the `proc` is either a class body or a method body defined in Ruby. It is no longer set for a block that given to `define_method`. --- src/vm.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/vm.c') diff --git a/src/vm.c b/src/vm.c index e5b7de0da..37b7b3c4d 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2651,6 +2651,7 @@ RETRY_TRY_BLOCK: } else { p = mrb_proc_new(mrb, nirep); + p->flags |= MRB_PROC_SCOPE; } if (c & OP_L_STRICT) p->flags |= MRB_PROC_STRICT; regs[a] = mrb_obj_value(p); -- cgit v1.2.3