O
Owein Herrmann
Hello Rubyists,
I am trying to define a helper method which displays a ruby expression
and then displays the results of that expression via puts. Initially I
did this, which obviously did not work:
def peval( expression )
puts expression
puts eval( expression )
puts ""
end
of course when I ran it, the scope of the method does not include
objects in the calling scope... so then I realized it had to do with
bindings and I defined this:
def peval
f,b = yield
puts f
puts eval(f,b)
puts ""
end
and this works, but, its really ugly:
peval { ["map.inspect", binding()] }
so my question is, is there a way to obtain the caller's binding so that
I do not have to specify it in the call? Is this in Pickaxe and I spaced
out on that section? I eally just want to be able to specify the
expression (in quotes), get it to display, see the results, move on...
I am trying to define a helper method which displays a ruby expression
and then displays the results of that expression via puts. Initially I
did this, which obviously did not work:
def peval( expression )
puts expression
puts eval( expression )
puts ""
end
of course when I ran it, the scope of the method does not include
objects in the calling scope... so then I realized it had to do with
bindings and I defined this:
def peval
f,b = yield
puts f
puts eval(f,b)
puts ""
end
and this works, but, its really ugly:
peval { ["map.inspect", binding()] }
so my question is, is there a way to obtain the caller's binding so that
I do not have to specify it in the call? Is this in Pickaxe and I spaced
out on that section? I eally just want to be able to specify the
expression (in quotes), get it to display, see the results, move on...