I've been investigating why the behaviour of ClassMethod#restore_original_method
is different between Ruby 1.8.x and all others versions. See line 77 of ClassMethod.
It turns out that there appears to be a problem in 1.8.7 with using define_method
when the method
argument is a singleton method. This can be illustrated with the following code:
class Foo
class << self
def my_class_method
'Foo.my_class_method'
end
end
end
class Bar < Foo; end
p Foo.my_class_method #=> 'Foo.my_class_method'
p Bar.my_class_method #=> 'Foo.my_class_method'
class Foo
M = method(:my_class_method)
class << self
define_method :my_class_method, M
end
end
p Foo.my_class_method #=> 'Foo.my_class_method'
p Bar.my_class_method #=> singleton method bound for a different object (TypeError)
Other reports of this behaviour:
- https://www.ruby-forum.com/topic/72973
- http://kagemusha.rubyforge.org/svn/trunk/kagemusha/test/test_bugs.rb
It's not clear whether this was a bug that's now been fixed.