From: "alanwu (Alan Wu) via ruby-core" Date: 2023-02-03T19:42:41+00:00 Subject: [ruby-core:112209] [Ruby master Bug#14083] Refinement in block calling incorrect method Issue #14083 has been updated by alanwu (Alan Wu). Status changed from Open to Rejected This is working as intended. Scoping rules for refinements is similar to the scoping rules for constant resolution. The scope only changes when one uses the `class`/`module` keyword. In the posted example the two `using` calls act on the same scope; the refinement scope does not end when the block scope ends. See also: https://bugs.ruby-lang.org/issues/11779#note-31 ---------------------------------------- Bug #14083: Refinement in block calling incorrect method https://bugs.ruby-lang.org/issues/14083#change-101640 * Author: bjfish (Brandon Fish) * Status: Rejected * Priority: Normal * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Tested on ruby versions 2.3.4 and 2.4.1 When a refinement is used inside a block, the scope of the refinement is not ending when the block has ended. The following example illustrates the issue: Example: ~~~ ruby class Example def test puts "Example#test" end end module M1 refine Example do def test puts "Example#test in M1" end end end module M2 refine Example do def test puts "Example#test in M2" end end end e = Example.new [M1, M2].each { |r| e.test using r e.test } ~~~ Actual Output ~~~ text Example#test Example#test in M1 Example#test in M1 Example#test in M2 ~~~ Expected output ~~~ text Example#test Example#test in M1 Example#test Example#test in M2 ~~~ -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/