From: Xavier Noria Date: 2007-10-22T14:25:49+09:00 Subject: Re: How does overload work in ruby? On Oct 22, 2007, at 7:17 AM, Shuaib Zahda wrote: > Hello guys > > I was trying to overload one method but it does not work like Java. > I noticed it only uses the first method that it meets. > > is there any special way for overloading in ruby. > > class Overloading > > def sum(a, b) > return a + b > end > > def sum(a, b, c) > return a + b + c > end Ruby does not support method overloading that way. As you founded out only one of the definitions of sum survives. However, you can define defaults for optional parameters like this: def sum(a, b, c=0) a + b + c end -- fxn