Issue #7872 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Rejected

I'll mark this request as rejected, as it appears based on the misconception that `block_given?` was `false` while `yield` would actually succeed; both refer correctly to the outerscope's presence of the block and arguments, including the block, must be declared explicitly as Koichi points out.

Moreover the request is woefully incomplete as it stands.
If someone feels like there is a feature to be requested, a sensible and more complete proposal must be made, in particular saying if all of `block_given?`, `yield`, `Proc.new`, eval(...), etc..., should refer to the inner scope and why, how this would affect `define_method(:foo, &block)` (where block is defined somewhere else; would `block_given?` & al. be magically rebound?), would it apply to `define_singleton_method`, etc..., why that would be a good thing and what kind of incompatibilities we should expect.
----------------------------------------
Feature #7872: `block_given?` does not work inside `define_method`
https://bugs.ruby-lang.org/issues/7872#change-38506

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
Is this the expected behavior?

 define_method :try do
   block_given? ? yield : 'no block'
 end

 try { 'block' } # => "no block"

However:

 def try_again
   block_given? ? yield : 'no block'
 end

 try_again { 'block' } # => "block"

=end



-- 
http://bugs.ruby-lang.org/