开发者

Case selection in Ruby

开发者 https://www.devze.com 2023-01-16 00:40 出处:网络
Here is my code: case input when \"quit\" || \"exit\" break end Only \"quit\" works here and not \"exit\".

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消