From: Robert Klemme Date: 2006-01-07T01:57:59+09:00 Subject: Re: How to override Numeric class Bojan Mihelac wrote: > Hi all, > I am new to Ruby and am trying to overload "+" operator on Integer > class, without success. > > class TestNum < Integer > def +(other) > self.value - other > end > end > > puts TestNum.new(5)+5; # should return 0 > > I know that it should be simple, but.... any help appreciated. Did you look at the error? ?> TestNum.new(5)+5 NoMethodError: undefined method `new' for TestNum:Class from (irb):7 from :0 Your problem starts already with the creation... Integer is an abstract class and I suspect it does something to #new. You should also look at #coerce, see http://www.rubygarden.org/ruby?CoerceExplanation for example if you want to implement operators properly. Kind regards robert