Bug #2117: Binding to a class, a method from the class's superclass's metaclass, fails
http://redmine.ruby-lang.org/issues/show/2117

Author: Shane O'Brien
Status: Open, Priority: Normal
ruby -v: ruby 1.9.1p0 (2009-01-30 revision 21907) [x86_64-linux]

I guess the best way to explain this is with an example:

>> class A; def self.foo; 'bar'; end; end
=> nil
>> class B < A; end
=> nil
>> A.method(:foo).unbind.bind(B)
TypeError: singleton method called for a different object
        from (irb):3:in `bind'
        from (irb):3
        from /usr/bin/irb1.9:12:in `<main>'

I've tried this on Ruby 1.8.5, 1.8.6, 1.8.7, 1.9.0 and 1.9.1 and I get this behaviour. It works in JRuby however. It's quite trivial to fix. I've attached a patch below, after the application of which Ruby's behaviour is:

>> class A; def self.foo; 'bar'; end; end
=> nil
>> class B < A; end
=> nil
>> A.method(:foo).unbind.bind(B).call
=> "bar"
>> a = A.new
=> #<A:0x00000000b1d870>
>> b = B.new
=> #<B:0x00000000b18230>
>> a.define_singleton_method(:foo){'baz'}
=> #<Proc:0x00000000b10df0@(irb):6 (lambda)>
>> a.method(:foo).unbind.bind(b)
TypeError: singleton method called for a different object
	from (irb):7:in `bind'
	from (irb):7
	from ./irb:12:in `<main>'

I think this makes more sense.


----------------------------------------
http://redmine.ruby-lang.org