From: ara.t.howard@... Date: 2006-10-18T05:43:28+09:00 Subject: Re: ruby way to say this? On Wed, 18 Oct 2006, 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: > > (temp = oneThing()).nonzero? ? temp : otherThing() > > I don't like it. Is that culturally correct, or is there a ruby way to > speak here, that I'm not thinking of? Thx - m. why not write in ruby what you are saying in english? harp:~ > cat a.rb def one_thing() 0 end def other_thing() 1 end p [one_thing, other_thing].detect{|thing| not thing.zero?} def one_thing() 42 end def other_thing() 0 end p [one_thing, other_thing].detect{|thing| not thing.zero?} harp:~ > ruby a.rb 1 42 ?? -a -- my religion is very simple. my religion is kindness. -- the dalai lama