比較簡單的 if / else statement
如:
if some_condition
something
else
something_else
end
其實可以簡化成 :
some_condition ? something : something_else
雖說 Ruby 提供這樣的簡化方式,但儘量還是不要濫用。如果超過兩層還是要將之拆開
# bad
some_condition ? (nested_condition ? nested_something : nested_something_else) : something_else
# good
if some_condition
nested_condition ? nested_something : nested_something_else
else
something_else
end