M
matt neuburg
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()?therThing()
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.
with the middle term omitted. So e.g. I'd like to say [pseudo-code from
some other language]:
oneThing()?therThing()
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.