From: Luciano Ramalho Date: 2007-02-09T15:18:00+09:00 Subject: Re: Your favorite bit of ruby code? John's snipped is brilliant. I just thought the last line could be like this: ###### # Ruby is Objects all the way down and open for extension... class Integer def factorial return 1 if self <= 1 self * (self-1).factorial end end puts 1000.factorial ###### Using puts makes it work outside of irb, and 1000.factorial shows off Bignum. It's a pity the factorial method can't be named just "!"... Cheers, Luciano On 2/9/07, Luciano Ramalho wrote: > On 2/8/07, John Carter wrote: > > # Ruby is Objects all the way down and open for extension... > > > > class Integer > > def factorial > > return 1 if self <= 1 > > self * (self-1).factorial > > end > > end > > > > 6.factorial > > 720 > > > > > > > > > > John Carter Phone : (64)(3) 358 6639 > > Tait Electronics Fax : (64)(3) 359 4632 > > PO Box 1645 Christchurch Email : john.carter@tait.co.nz > > New Zealand > > > > > > >