Discussion:
The Binding of the calling method
Peter Hanning
2006-11-14 05:59:49 UTC
Permalink
Someone (Ben?) asked at the last meeting about finding the calling method's
Binding. I happened to stumble upon this today;
http://extensions.rubyforge.org/rdoc/index.html. Check out the Binding
extension. Is this what you were looking for?

Pardon my ignorance but will the parent binding still be valid, having
exited and restarted irb like what was shown in the demo? Or was the intent
simply to reach back into the main irb Binding of the one and the same irb
session from a method defined in .irbrc?

Peter, Ruby newbie
b***@bleything.net
2006-11-14 17:10:38 UTC
Permalink
Post by Peter Hanning
Someone (Ben?) asked at the last meeting about finding the calling method's
Binding. I happened to stumble upon this today;
http://extensions.rubyforge.org/rdoc/index.html. Check out the Binding
extension. Is this what you were looking for?
Yup, that was me. Thanks for pointing that out. Some other folks on
ruby-talk
had found that, but it turns out it relied on a bug in Ruby that was fixed in
1.8.5. Bummer for me.
Post by Peter Hanning
Pardon my ignorance but will the parent binding still be valid, having
exited and restarted irb like what was shown in the demo? Or was the intent
simply to reach back into the main irb Binding of the one and the same irb
session from a method defined in .irbrc?
The latter. To demonstrate the problem, consider this code:

def foo
eval "bar = :whammo"
end

If you call the foo method, it'll return :whammo (the result of the eval), but
since bar was defined inside foo's binding, you won't have access to it.

Since the point of my hack is to allow you to replay history, I need
the eval to
run in the scope of whatever calls foo. Some people have suggested
workarounds,
but I haven't had a chance to experiment yet.

If you're interested, check out the thread on ruby-talk here:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/224300

Ben

Loading...