Case selection in Ruby
Here is my code:
case input
when "quit" || "exit"
break
end
Only "quit" works here and not "exit".
How could I have "exit" work 开发者_Go百科too without having to have a new "when" line?
case input
when "quit", "exit"
break
end
||
operator evaluates the latter when the former is nil. "quit"
is not nil. So "quit" || "exit"
is "quit"
.
精彩评论