Project

General

Profile

Actions

Feature #7986

closed

Custom case statement comparison method

Added by trans (Thomas Sawyer) about 11 years ago. Updated over 3 years ago.

Status:
Feedback
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

Like0
Like0Like0Like0Like0Like0Like0Like0