end end # case ではなく in ( パターン側) が使われる case nil in Tester puts "nil matched" end 1 2 3 4 5 6 7 8 9 10 11 12 https://github.com/kokuyouwind/pattern_match_demo/blob/master/src/03_constant.rb
Type = pattern do case self.type in :official; [' 公式'] in :user; [' ユーザ'] end end # ... 1 2 3 4 5 6 7 8 9 10 11 12 13 https://github.com/kokuyouwind/pattern_match_demo/blob/master/src/15_active_pattern_presenter.rb
in :prepare; [' 準備中'] in :onair; [' 放送中'] in :closed; [' 放送済み'] end end All = pattern { self in Type[type]; self in Status[status]; { type: type, status: status } } end 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 https://github.com/kokuyouwind/pattern_match_demo/blob/master/src/15_active_pattern_presenter.rb