奇妙に聞こえるかもしれませんが、私は次のようなことをしたいと思っています。
case cool_hash
when cool_hash[:target] == "bullseye" then do_something_awesome
when cool_hash[:target] == "2 pointer" then do_something_less_awesome
when cool_hash[:crazy_option] == true then unleash_the_crazy_stuff
else raise "Hell"
end
理想的には、has を再度参照する必要さえありません。これは case ステートメントに関するものだからです。オプションを 1 つだけ使用したい場合は、「case cool_hash[:that_option]」としますが、任意の数のオプションを使用したいと考えています。また、Ruby の case ステートメントは最初の true 条件付きブロックのみを評価することを知っています。これをオーバーライドして、ブレークがない限り true であるすべてのブロックを評価する方法はありますか?