From: Jason Roelofs Date: 2007-02-09T06:45:45+09:00 Subject: Re: Your favorite bit of ruby code? ------=_Part_9761_31647552.1170971143219 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Can't say I've used this bit of code anywhere, but it's the same feature as John's post, with a twist: class NilClass def to_s "Hi! My name is Nil! You can call me Nil!" end end puts nil.to_s #=> "Hi! My name is Nil! You can call me Nil!" I love ruby! Jason On 2/8/07, John Carter wrote: > > On Fri, 9 Feb 2007, Carl Lerche wrote: > > > > > I'm just curious what your favorite bit of ruby code is? Do you have > > any small bits, methods, classes, or anything else, that just make you > > say "Wow, that is sweet!" > > # 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 > > > ------=_Part_9761_31647552.1170971143219--