How do I use the conditional operator (? :) in Ruby?
It is the ternary operator, and it works like in C (the parenthesis are not required). It’s an expression that works like: if_this_is_a_true_value ? then_the_result_is_this : else_it_is_this However, in Ruby, if is also an expression so: if a then b else c end === a ? b : c, except for precedence issues. Both are … Read more