Strange, it is “fixed” in 1.9 (though I have an old version ruby 1.9.0
(2008-06-20 revision 17482) [i486-linux]
). But but then Jruby behaves like 1.8, maybe this is defined
somewhere?
If we look at the warning below it really seems like a bug, 'cause the
old method is not discarded.
516/16 > cat xxx.rb && ruby1.9 -v xxx.rb && ruby -v xxx.rb && jruby -v
xxx.rb
class X
def self.inherited(x);
x.send :define_method, :a do puts 42 end
end
end
class Y < X
def a; puts “21*2” end
end
Y::new.a
puts "-"72
Class::new Y do
def a; puts “222.to_i(4)” end
end::new.a
ruby 1.9.0 (2008-06-20 revision 17482) [i486-linux]
xxx.rb:11: warning: method redefined; discarding old a
212
xxx.rb:16: warning: method redefined; discarding old a
222.to_i(4)
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]
xxx.rb:11: warning: method redefined; discarding old a
21*2