title: Why doesn't `block_given?` work in this dynamically-defined method?
body: <p>When I write methods that take an optional block, I typically use something like</p>
  
  <pre><code>block.call if block_given?
  </code></pre>
  
  <p>However, in method defined dynamically like the one below, <code>block_given?</code> doesn't seem to work.</p>
  
  <pre><code>class Foo
    %w[bar baz].each do |method_name|
      define_singleton_method(method_name) do |&amp;block|
        puts "Was #{method_name} given a block? #{block_given?}"
        puts block.call
      end
    end
  end
  
  Foo.bar { puts 'I am a block' }
  </code></pre>
  
  <p>The block is called as expected, but <code>block_given?</code> returns false.</p>
  
  <p>Why is this?</p>