Michael Fellinger wrote:
> I found some strange behaviour with the binding method today, first
> comes the issue, afterwards my solution.
> I would like to know if i should file a bug for this on redmine.

I believe this was brought up before and determined to be correct 
behavior for 1.9 (or else send :binding behavior is unspecified and you 
shouldn't depend on it).

In 1.8 binding could be sent to objects and the resulting binding used 
that object as self. In 1.9, binidng always returns the caller self, 
which is more consistent (since it's a kernel method and everything else 
comes from the caller).

In your fix, you're actually calling the kernel binding from within an 
instance of A, instead of from toplevel, so it's using that A instance 
as self.

Note that in most other implementations of Ruby other than 1.8, you'll 
see the 1.9 behavior as well. So it's probably best not to depend on 
send :binding behavior.

- Charlie

> == Problem ==
> 
> sigma ~ % cat send_binding.rb
> class A
> end
> 
> binding = A.new.__send__(:binding)
> binding.eval('p self => self.class')
> 
> sigma ~ % ruby -v send_binding.rb
> ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
> {#<A:0x7f5b1d32f7b0>=>A}
> 
> sigma ~ % ruby19 -v send_binding.rb
> ruby 1.9.1p5000 (2009-01-26 trunk 21781) [x86_64-linux]
> {main=>Object}
> 
> == Solution ==
> 
> sigma ~ % cat send_binding_fix.rb
> class A
>   def binding; super; end
>   private :binding
> end
> 
> binding = A.new.__send__(:binding)
> binding.eval('p self => self.class')
> 
> sigma ~ % ruby -v send_binding_fix.rb
> ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
> {#<A:0x7f9d63518508>=>A}
> 
> sigma ~ % ruby19 -v send_binding_fix.rb
> ruby 1.9.1p5000 (2009-01-26 trunk 21781) [x86_64-linux]
> {#<A:0x000000027074a0>=>A}
>