Daniel Sche wrote: > > irb(main):005:0> class << c > > irb(main):006:1> def angle > > irb(main):007:2> (arg/Math::PI)*180 > > irb(main):008:2> end > > irb(main):009:1> end > > TypeError: can't define singleton method "angle" for Complex > > from (irb):6 > > from :0 > > irb(main):010:0> c.arg > > => 0.785398163397448 > > irb(main):011:0> c.angle > > => 45.0 > > I think the error message is misleading, because > > class << c > def angle;end > end > > should add a singleton method to instance c > or overwrite the behavior of inherited method > > as expected the behaviuor of c.angle is changed > > it should not "define singleton method for Complex" > > Regards, Daniel > You are correct. What Nobu said is that you'll see a more helpful message when it's easier to do so. At the moment, it seems, the method is defined in your singleton object then an exception is raised with a misleading message. IRB traps the error and continues. require 'complex' c=Complex.new 1,1 begin def c.angle (arg/Math::PI)*180 end rescue => e p e end #<TypeError: can't define singleton method "angle" for Complex> p c.arg #.->=> 0.785398163397448 p c.angle #.->=> 45.0 # Complex is unchanged c2=Complex.new 1,1 p c2.arg #.->=> 0.785398163397448 p c2.angle #.->=> 0.785398163397448 daz