From: Phillip Gawlowski Date: 2011-10-04T14:22:55+09:00 Subject: Re: Operator Overloading On Tue, Oct 4, 2011 at 7:11 AM, Thescholar Thescholar wrote: > Let's suppose I have a class like this one and then I create two > objects: > > =-=-=-=-=-=-=-=-=-=-=-= > class Point > >  def initialize >    x = 5 >    y = 10 >    z = 25 >  end > > end > > a = Point.new > b = Point.new > =-=-=-=-=-=-=-=-=-=-=-= > > How do I do if I want to add a and b together to a new point called c? > Example: > > c = a + b > > How exactly should I implement the operator overloading feature? So that > x = 10, y = 20, z = 50. There are hardly any tutorial for this... Ruby doesn't do operator overloading. But that doesn't matter, since "+" is a method. Thus: class Point def self.+(obj) # Details of addition end end -- Phillip Gawlowski gplus.to/phgaw | twitter.com/phgaw A method of solution is perfect if we can forsee from the start, and even prove, that following that method we shall attain our aim.               -- Leibniz