NoMatchingPatternError#=== doesn't match an instance of NoMatchingPatternKeyError, even though NoMatchingPatternError is the superclass of NoMatchingPatternKeyError.
This is the behavior I see from CRuby (3.3, 3.4, 4.0), tested in irb:
NoMatchingPatternError === NoMatchingPatternKeyError.new("message", matchee: :foo, key: :bar)
=> true
Here's what I see with RBENV_VERSION=jruby-10.0.5.0 irb
NoMatchingPatternError === NoMatchingPatternKeyError.new("message", matchee: :foo, key: :bar)
=> false
This is mostly relevant for rescue clause matching, e.g:
def foo(*args, **kwargs)
case [*args, kwargs]
in /\A(hi|hello)\z/, {world: COMPATIBLE_WORLDS}
do the thing
end
rescue NoMatchingPatternError # should match NoMatchingPatternKeyError, but doesn't
raise ArgumentError, "etc, etc, ..."
end
NoMatchingPatternError#===doesn't match an instance ofNoMatchingPatternKeyError, even thoughNoMatchingPatternErroris the superclass ofNoMatchingPatternKeyError.This is the behavior I see from CRuby (3.3, 3.4, 4.0), tested in irb:
Here's what I see with
RBENV_VERSION=jruby-10.0.5.0 irbThis is mostly relevant for
rescueclause matching, e.g: