C
Chris Thomas
But then you get some larger ones:
set.map { |e|
if something
e.x
else
e.y
end
}
[Robert:]
Know your ternary operator:
set.map { |e| something ? e.x : e.y }
I know my ternary operator, but:
- in my code snippet, "something", "e.x", and "e.y" were placeholders
for something far bigger than you or I could imagine
- sometimes there is multi-part processing do be done before arriving
the "return value" for the block
Also
- The ternary operator is idiomatic of expert (or expert-wannabe) use
of the C family of languages and likely to confuse and even scare away
novice Ruby users who aren't from that segment of the population, or
only have limited experience with C.
Chris