From: "shugo (Shugo Maeda)" Date: 2013-12-04T11:54:53+09:00 Subject: [ruby-core:58843] [Backport 200 - Backport #8872] Case statements do not honor a refinement of the '===' method Issue #8872 has been updated by shugo (Shugo Maeda). jballanc (Joshua Ballanco) wrote: > To play devil's advocate, I think the opposing question to be asked is "how would you alter the behavior of case evaluation using refinements"? > > It may be, as shugo states, that refinements are not meant to be used for altering the behavior of expressions. In this case, the answer to the question I posed is, simply, "you don't." > > That said, I think it is fairly well understood in the Ruby community that "===" is related to case. I've even heard the operator described as "case equality". Playing devil's advocate again, what is the use case for refining "===" if it _doesn't_ affect the evaluation of a case...when clause? I don't come up with any use case for refining "===" regardless of whether it affects the evaluation of a case expression or not. I'm neutral about this issue, and really want to know use cases. ---------------------------------------- Backport #8872: Case statements do not honor a refinement of the '===' method https://bugs.ruby-lang.org/issues/8872#change-43402 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/