Im trying to do some metaprogramming and would like to know the names of the variables passed as block arguments:
z = 1 # this variable is still local to the block
Proc.new { |x, y| local_variables }.call
# => ['_', 'z', x', 'y']
I am not quite sure how to differentiate between the variables defined outside the block and the block arguments in this list. Is there any other way to reflect this?
Here’s how you can tell in Ruby 1.8:
but, caution! this doesn’t work in Ruby 1.9 – you’ll get
and I don’t know the answer then.