From: Robert Dober Date: 2007-08-04T04:46:32+09:00 Subject: Re: Getting the 'Sender' or 'Caller' object of a method On 8/3/07, ara.t.howard wrote: > > On Aug 3, 2007, at 11:50 AM, Trans wrote: > > > You can always take a block and get the binding from it: > > > > def method(&b) > > callers_binding = b.send(:binding) > > end > > > > I works always. Yes, it means passing a block, but sometimes that's > > useful anyway. > > > > ?? > > cfp:~ > cat a.rb > def a &b > eval 'self', b.send(:binding) > end > > require 'binding_of_caller' > def b > Binding.of_caller{|binding| eval 'self', binding} > end > > p self > p a > p b > > > cfp:~ > ruby a.rb > main > nil > main > > > cfp:~ > ruby -v > ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1] > > > am i misunderstanding? yup, Tom asks us to kindly pass him a block p a {} one could consider it cheating, but it is incredibly useful, I did not know about it. Thx and Cheers Robert -- [...] as simple as possible, but no simpler. -- Attributed to Albert Einstein