From: matt@... (matt neuburg) Date: 2006-10-18T05:20:17+09:00 Subject: Re: ruby way to say this? Simon Kr�ger wrote: > matt neuburg wrote: > > In Ruby, zero isn't false and there is no equivalent of the ?: operator > > with the middle term omitted. So e.g. I'd like to say [pseudo-code from > > some other language]: > > > > oneThing()?:otherThing() > > > > meaning, if oneThing is nonzero, return oneThing, else return > > otherThing. Now, I don't want to evaluate oneThing twice, so I've ended > > up with this: > > Well, most of the time just ask ruby to do what you want: > > oneThing.nonzero? || otherThing > > -------------------------------------------------------------------------- > num.nonzero? => num or nil > > Returns num if num is not zero, nil otherwise. Thx, I feel better now! m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Tiger - http://www.takecontrolbooks.com/tiger-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com