From: "matz (Yukihiro Matsumoto)" Date: 2013-11-29T19:10:52+09:00 Subject: [ruby-core:58683] [Backport 200 - Backport #8872] Case statements do not honor a refinement of the '===' method Issue #8872 has been updated by matz (Yukihiro Matsumoto). The basic principle of refinements is that refinement do work in local scope. So methods called from the scope will be refined but method called from methods called will not. And very importantly, "===" called from case statement is controversial. It can be viewed as a method called from case statement, or case statement itself is just a syntax sugar wrapping "===" calls. From the former point of view, refine should not affect "===", but from the latter POV, refinement should change the behavior. Right now, we took the former POV, and OP expected the latter. So I would like to hear from others. Matz. ---------------------------------------- Backport #8872: Case statements do not honor a refinement of the '===' method https://bugs.ruby-lang.org/issues/8872#change-43250 Author: jconley88 (Jon Conley) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: =begin Below, I've redefined the ((|===|)) method of symbol to always return true. In ((|RefineTest#uses_refinement|)), I call ((|===|)) directly and the refined method is called. In ((|RefineTest#does_not_use_refinement|)), the ((|===|)) method is called indirectly through a case statement. If the refined ((|===|)) method was called, the result should be ((*'The refinement was used'*)), but this code currently returns ((*'The refinement was not used'*)). module RefineSymbol refine Symbol do def ===(other) true end end end using RefineSymbol class RefineTest def uses_refinement :a === :b end def does_not_use_refinement case :a when :b 'The refinement was used' else 'The refinement was not used' end end end rt = RefineTest.new rt.uses_refinement # => true rt.does_not_use_refinement # => expected 'The refinement was used' but got 'The refinement was not used' =end -- http://bugs.ruby-lang.org/