Gregory Brown
1/21/2007 7:54:00 PM
On 1/21/07, kelly <railsinator@gmail.com> wrote:
> myproc.methods returns the methods of the proc object itself. The proc
> object, I guess, is a container for the original block. I'm interested
> in the contents of the original block.
>
> Any suggestions for exposing details about the original block?
this seems just plain evil, so please think about why you'd ever do
it, and also, look for better solutions! :)
seltzer:~ sandal$ irb
>> class Proc
>> def eval_with_binding(string)
>> eval string, binding
>> end
>> end
=> nil
>> b = 20
=> 20
>> a = lambda { |x| x + b }
=> #<Proc:0x0032ce84@(irb):7>
>> a.eval_with_binding("local_variables")
=> ["_", "__", "b", "a"]
>> class B
>> def local_vars_for_proc(p)
>> p.eval_with_binding("local_variables")
>> end
>> end
=> nil
>> c = B.new
=> #<B:0x31b3dc>
>> c.local_vars_for_proc(a)
=> ["_", "__", "b", "a", "c"]