From: "drbrain (Eric Hodel)" Date: 2013-03-01T12:56:19+09:00 Subject: [ruby-core:53061] [ruby-trunk - Feature #7986] Custom case statement comparison method Issue #7986 has been updated by drbrain (Eric Hodel). =begin Why not use the features of case statements properly? For classes, place the subclass above the superclass. For array inclusion, use splat: class Foo; end class Bar < Foo; end def case_klass obj case obj when Bar p "Bar!" when Foo p "Foo, not Bar!" end end case_klass Foo.new case_klass Bar.new def case_include obj case obj when *%w[b] p "b includes name, not a" when *%w[a] p "a includes name" else p "neither a or b includes name" end end case_include 'a' case_include 'b' case_include 'c' =end ---------------------------------------- Feature #7986: Custom case statement comparison method https://bugs.ruby-lang.org/issues/7986#change-37215 Author: trans (Thomas Sawyer) Status: Open Priority: Normal Assignee: Category: core Target version: Next Major =begin Case statements use #=== to handle matching, but sometimes this can be limiting. It such cases it would be helpful to be able to specify the comparison method. So I wondered if that could be done by hanging the method off the `case` keyword, e.g. class Bar < Foo; end case == obj.class when Foo p "Foo, not Bar!" when Bar p "Bar!" end And case.include? name when a p "a includes name" when b p "b includes name, not a" else p "neither a or b includes name" end =end -- http://bugs.ruby-lang.org/