Issue #7872 has been updated by drbrain (Eric Hodel).

Tracker changed from Bug to Feature
Target version set to next minor

=begin
The behavior in 1.9:

  $ ruby19 -ve 'class C; define_method :x do p block_given? end; end; C.new.x { }' 
  ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
  false

Is the same as in 2.0:

  $ ruby20 -ve 'class C; define_method :x do p block_given? end; end; C.new.x { }' 
  ruby 2.0.0dev (2013-02-08 trunk 39138) [x86_64-darwin12.2.1]
  false

So I have switched it to a feature request.
=end

----------------------------------------
Feature #7872: `block_given?` does not work inside `define_method`
https://bugs.ruby-lang.org/issues/7872#change-36354

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: 
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/