From: marcandre-ruby-core@... Date: 2020-12-07T18:22:49+00:00 Subject: [ruby-core:101288] [Ruby master Bug#17374] Refined methods aren't visible from a refinement's module Issue #17374 has been updated by marcandre (Marc-Andre Lafortune). Eregon (Benoit Daloze) wrote in #note-2: > I think so. Refined methods only see each other if they are directly defined in the `refine`. They can be defined in different `refine` blocks and it still works: ```ruby class Foo module Extension refine Foo do def foo super(bar) end end refine Foo do def bar 42 end end end def foo(value = :none) p value end end using Foo::Extension Foo.new.foo # => 42 ``` > Using `prepend`/`include` is probably not recommended anyway, it leads to many complications in the semantics. It's not clear to me why they are allowed if they are supported this way. I know of no other case in Ruby where two methods in a module can not see each other. I know of no other case in Ruby where you can not extract some code in a new method (assuming no naming conflict) Let's say a class does not define any methods; I know of no other case in Ruby where `include Mod` or copy-pasting `Mod`'s methods is different. In my mind, `include/prepend` inserts a layer inside a Module and brings in those methods in it. I can not explain mentally what `refine { include }` does currently. Here's a simplified example, where a method does not see itself: ``` module Extension module Implementation def foo(value = nil) return value.to_s if value foo(42) # => NoMethodError!? end end refine Object do include Implementation end end using Extension :x.foo(:y) # => 'y' (ok) :x.foo # => NoMethodError ``` Finally, my use case is that I think it would be worthwhile to provide a way to write libraries that can be used either as a refinement, or as a apply everywhere: ```ruby # Either using MySuperGem # => everywhere you use the refinement # Or SomeClass.prepend MySuperGem # => once ``` This is *much* harder to write with the current semantics. ---------------------------------------- Bug #17374: Refined methods aren't visible from a refinement's module https://bugs.ruby-lang.org/issues/17374#change-88972 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- -- https://bugs.ruby-lang.org/ Unsubscribe: