From: Gavin Kistner Date: 2006-10-18T04:49:26+09:00 Subject: Re: ruby way to say this? From: Louis J Scoras [mailto:louis.j.scoras@gmail.com] > How about: > > def if_zero(exp,alt) > exp == 0 ? alt : exp > end > > x = 0 > > if_zero( (x+=1) + 1, 7) # => 2 > if_zero( x-=1 , 8) # => 8 > > So your original would look like: > > # if_zero(one_thing, other_thing) Let's make that more OO-pretty (using a goofy name): class Numeric def or_if_zero( alternate_value ) self.nonzero? ? self : alternate_value end end Which makes the code: oneThing().or_if_zero( otherThing() )