Issue #7986 has been updated by drbrain (Eric Hodel).


=begin
It is puzzling that you must always super first, then if unhandled execute the case expression, but do nothing if the object is unknown.  It seems very error prone.

Why not execute the subclass case expression first, then super in its else?

As such, I agree with Martin that there is something wrong with your design. If you study design patterns you'll find that dispatching to methods is preferred (such as in the visitor pattern) to using comparison constructs due to the inflexibility that your design displays.

A case expression can already handle URI matching just fine:

  case uri
  when /\Ahttps:/i then ???
  when /\Ahttp:/i then ???
  when /\Aftp:/i then ???
  else ???
  end

or if you use URI objects:

  case uri
  when URI::HTTPS then ???
  when URI::HTTP then ???
  when URI::FTP then ???
  else ???
  end

or:

  case uri.scheme.downcase
  when 'https' then ???
  when 'http' then ???
  when 'ftp' then ???
  else ???
  end

=end
----------------------------------------
Feature #7986: Custom case statement comparison method
https://bugs.ruby-lang.org/issues/7986#change-37243

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/