Project

General

Profile

Actions

Feature #7986

open

Custom case statement comparison method

Added by trans (Thomas Sawyer) almost 9 years ago. Updated 12 months ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:53035]

Description

=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

Actions

Also available in: Atom PDF