From: Rick DeNatale Date: 2007-10-22T21:31:03+09:00 Subject: Re: How does overload work in ruby? On 10/22/07, Bertram Scharpf wrote: > Am Montag, 22. Okt 2007, 14:25:49 +0900 schrieb Xavier Noria: > > def sum(a, b, c=0) > > a + b + c > > end > > If you want to allow the caller to select the default value > explicitly you may say > > def sum a, b, c = nil > c ||= 0 > a + b + c > end It seems to me that this is just a slightly less efficient way of doing the same thing as the code you quoted. In either case the caller isn't specifying the default value, it's overriding the default. In the call sum(1,2) ruby will evaluate the default expression for c, in the call sum(1,2,3) it won't since c has a value given by the third parameter. Making the default value of c nil, and then doing c ||= 0 justs slows down both cases. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/