From: merch-redmine@... Date: 2020-12-07T20:31:33+00:00 Subject: [ruby-core:101293] [Ruby master Bug#17374] Refined methods aren't visible from a refinement's module Issue #17374 has been updated by jeremyevans0 (Jeremy Evans). I do not think this is a bug. The question to ask yourself is, at the point of call, is the refinement active?. So in method `Implementation#foo`, we are talking about the call to `bar`: ```ruby def foo super(bar) # << Can not see bar end ``` No, the refinement is not active at that point. You can make it active, though doing so is probably not obvious: ```ruby class Foo module Extension module Implementation end refine Foo do prepend Implementation end module Implementation def foo super(bar) # << Can not see bar end def bar # << Bar is in the same module! 42 end end end def foo(value = :none) p value end end Foo.new Foo.new.foo # => :none (ok) # Does not work: undefined local variable or method `bar' using Foo::Extension Foo.new.foo rescue (p :error) # => :error # Works: Foo.send(:prepend, Foo::Extension::Implementation) Foo.new.foo # => 42 ``` This is because `refine` implicitly activates the refinement, so the refinement is active at the point `bar` is called. This approach works back to Ruby 2.0, with output: ``` :none :none 42 ``` ---------------------------------------- Bug #17374: Refined methods aren't visible from a refinement's module https://bugs.ruby-lang.org/issues/17374#change-88977 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: shugo (Shugo Maeda) * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- -- https://bugs.ruby-lang.org/ Unsubscribe: