From: Pete Yandell Date: 2006-10-27T08:29:45+09:00 Subject: Re: simple math question On 26/10/2006, at 9:25 AM, Robert Oliver wrote: > You can determine if a number is odd by doing this: > > class Fixnum > def odd? > if self % 2 == 0 > return nil > else > return true > end > end > def even? > if self % 2 == 0 > return true > else > return nil > end > end > end Argh! Ok, I keep coming across code like this, and it's driving me nuts. It's like writing: if true then true else false end Well, duh! :) Just write this: class Fixnum def odd? self % 2 == 1 end def even? self % 2 == 0 end end Pete Yandell http://notahat.com/