From: marcandre-ruby-core@... Date: 2020-12-08T04:01:53+00:00 Subject: [ruby-core:101303] [Ruby master Bug#17374] Refined methods aren't visible from a refinement's module Issue #17374 has been updated by marcandre (Marc-Andre Lafortune). jeremyevans0 (Jeremy Evans) wrote in #note-8: > After playing around with it, I found a way to get it to work without duplicating the literal method definitions. Ah! I had tried the other way (doesn't work), but from refinement module to the module it works, thanks for figuring this out ���� > It's not much better than calling `class_eval` with the same string in two places I think it is. A string isn't parsable (e.g. RuboCop, AST-based search tools, ...), nor syntax-highlightable, nor as debuggable, won't be detected by help generation tools, etc... This way I can write what I wanted: ``` class Foo module Extension import refine(Foo) { def foo super(bar) # << Can not see bar end def bar # << Bar is in the same module! 42 end } end def foo(value = :none) p value end end # Does not work: undefined local variable or method `bar' if ENV['USING'] using Foo::Extension else Foo.prepend Foo::Extension end Foo.new.foo rescue (p :error) # => 42, works both ways ``` With this refinement active... ```ruby refine Module do def import(refined_mod) refined_mod.instance_methods(false).each do |m| define_method(m, refined_mod.instance_method(m)) end end end ``` ---------------------------------------- Bug #17374: Refined methods aren't visible from a refinement's module https://bugs.ruby-lang.org/issues/17374#change-88991 * 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: