From: Robert Oliver Date: 2006-10-26T08:25:21+09:00 Subject: Re: simple math question ------=_Part_25446_27748441.1161818718048 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/25/06, Brad Tilley wrote: > > What's the quickest way to determine if an int is an even number > 2,4,6,8... > Anything such as int.even or int.odd returning true/false? I want to > test the length of an array and add one element to it if it has an odd > number of elements. > 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 Then just call it like this: 2.odd? and you'll get nil 3.odd? and you'll get true The above is messy, I'm sure it can be cleaned up, but you get the idea. -- Robert W. Oliver II President, OCS Solutions, Inc. - Web Hosting and Development http://www.ocssolutions.com/ Toll-Free Phone - 1-800-672-8415 OCS Ruby Forums - http://www.rubyforums.com/ My Blog - http://www.rwoliver.com/ ------=_Part_25446_27748441.1161818718048--