From: "(r.*n){2}" Date: 2010-09-28T12:00:09+09:00 Subject: Re: Operator Overload On Sep 27, 9:49 pm, Trevor Hinesley wrote: > Hey guys, > > I'm slowly getting the hang of Ruby, I'm a Java guy by trade. I really > like Ruby and am picking up on it pretty quickly, but for some reason my > overload of the "+" operator is not working. Here is the code: > > class Overloading > def -(a) >   return -a > end > b = 2-4 > puts "#{b}" > end > > Basically, I'm trying to turn the minus operator into a plus operator > for a project to show how operator overloading in Ruby works, but this > isn't working from some reason, and I'm not sure why. > > Help? > > Thanks, > > Trevor > -- > Posted viahttp://www.ruby-forum.com/. I think you have just defined the class called Overloading and have not instantiated it. Did you intend to do this? class Overloading def -(a) return -a end b = 2-4 puts "#{b}" end x = Overloading.new puts "#{x.-(5)}" puts "#{x - 5}" # same as x.-(5) above Output: -2 # this comes from the puts that is part of class definition -5 -5