开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜