* [ruby-core:101326] [Ruby master Feature#17380] Useful `include/prepend` in `refine`
@ 2020-12-09 4:31 marcandre-ruby-core
2020-12-09 18:43 ` [ruby-core:101348] " eregontp
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: marcandre-ruby-core @ 2020-12-09 4:31 UTC (permalink / raw
To: ruby-core
Issue #17380 has been reported by marcandre (Marc-Andre Lafortune).
----------------------------------------
Feature #17380: Useful `include/prepend` in `refine`
https://bugs.ruby-lang.org/issues/17380
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Currently, `prepend/include` within a `refine` block leads to a method not being to see itself, or others defined in the same module:
```ruby
module Code
def recurse(value = nil)
return value if value
recurse(42) # => NoMethodError!!!
end
end
module Extension
refine Object do
include Code
end
end
using Extension
:x.recurse(:y) # => :y (ok)
:x.recurse # => NoMethodError, was hoping for 42
```
I find this unintuitive and not useful.
The conclusion of the current situation from @shugo and others is ["I don't recommend module inclusion to define refined methods"](https://bugs.ruby-lang.org/issues/17374#note-9)
Could we change this situation so it can be recommended to use it?
What I believe would be more useful and is what I expected was that `include/prepend` within a `Module` would bring in the current methods in the Module, with the current refinements activated.
One use-case in particular is to publish libraries where one can give the option to the user to either:
- call `using GreatExtension` in each and every file that need it
- or `MyClass.prepend GreatExtension` once.
While [Jeremy Evans found a way to do it](https://bugs.ruby-lang.org/issues/17374#note-8), it remains challenging and unnatural.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:101348] [Ruby master Feature#17380] Useful `include/prepend` in `refine`
2020-12-09 4:31 [ruby-core:101326] [Ruby master Feature#17380] Useful `include/prepend` in `refine` marcandre-ruby-core
@ 2020-12-09 18:43 ` eregontp
2020-12-10 13:45 ` [ruby-core:101392] " daniel
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: eregontp @ 2020-12-09 18:43 UTC (permalink / raw
To: ruby-core
Issue #17380 has been updated by Eregon (Benoit Daloze).
Maybe we should allow `include RefinedImplementation` from https://bugs.ruby-lang.org/issues/17374#note-8 ?
Copying methods manually seems to have a very similar effect, but it would be more convenient.
----------------------------------------
Feature #17380: Useful `include/prepend` in `refine`
https://bugs.ruby-lang.org/issues/17380#change-89055
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Currently, `prepend/include` within a `refine` block leads to a method not being to see itself, or others defined in the same module:
```ruby
module Code
def recurse(value = nil)
return value if value
recurse(42) # => NoMethodError!!!
end
end
module Extension
refine Object do
include Code
end
end
using Extension
:x.recurse(:y) # => :y (ok)
:x.recurse # => NoMethodError, was hoping for 42
```
I find this unintuitive and not useful.
The conclusion of the current situation from @shugo and others is ["I don't recommend module inclusion to define refined methods"](https://bugs.ruby-lang.org/issues/17374#note-9)
Could we change this situation so it can be recommended to use it?
What I believe would be more useful and is what I expected was that `include/prepend` within a `Module` would bring in the current methods in the Module, with the current refinements activated.
One use-case in particular is to publish libraries where one can give the option to the user to either:
- call `using GreatExtension` in each and every file that need it
- or `MyClass.prepend GreatExtension` once.
While [Jeremy Evans found a way to do it](https://bugs.ruby-lang.org/issues/17374#note-8), it remains challenging and unnatural.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:101392] [Ruby master Feature#17380] Useful `include/prepend` in `refine`
2020-12-09 4:31 [ruby-core:101326] [Ruby master Feature#17380] Useful `include/prepend` in `refine` marcandre-ruby-core
2020-12-09 18:43 ` [ruby-core:101348] " eregontp
@ 2020-12-10 13:45 ` daniel
2020-12-10 13:58 ` [ruby-core:101393] " marcandre-ruby-core
2020-12-10 14:58 ` [ruby-core:101394] " daniel
3 siblings, 0 replies; 5+ messages in thread
From: daniel @ 2020-12-10 13:45 UTC (permalink / raw
To: ruby-core
Issue #17380 has been updated by Dan0042 (Daniel DeLorme).
It would be nice if `prepend`/`include` worked within a `refine` block, but if they don't then at least it should raise an error. In that respect I disagree with closing #17374; even if the result is "expected", the fact that including a module is effectively a no-op should be considered a bug. Silently failing to have an effect is not so good.
----------------------------------------
Feature #17380: Useful `include/prepend` in `refine`
https://bugs.ruby-lang.org/issues/17380#change-89151
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Currently, `prepend/include` within a `refine` block leads to a method not being to see itself, or others defined in the same module:
```ruby
module Code
def recurse(value = nil)
return value if value
recurse(42) # => NoMethodError!!!
end
end
module Extension
refine Object do
include Code
end
end
using Extension
:x.recurse(:y) # => :y (ok)
:x.recurse # => NoMethodError, was hoping for 42
```
I find this unintuitive and not useful.
The conclusion of the current situation from @shugo and others is ["I don't recommend module inclusion to define refined methods"](https://bugs.ruby-lang.org/issues/17374#note-9)
Could we change this situation so it can be recommended to use it?
What I believe would be more useful and is what I expected was that `include/prepend` within a `Module` would bring in the current methods in the Module, with the current refinements activated.
One use-case in particular is to publish libraries where one can give the option to the user to either:
- call `using GreatExtension` in each and every file that need it
- or `MyClass.prepend GreatExtension` once.
While [Jeremy Evans found a way to do it](https://bugs.ruby-lang.org/issues/17374#note-8), it remains challenging and unnatural.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:101393] [Ruby master Feature#17380] Useful `include/prepend` in `refine`
2020-12-09 4:31 [ruby-core:101326] [Ruby master Feature#17380] Useful `include/prepend` in `refine` marcandre-ruby-core
2020-12-09 18:43 ` [ruby-core:101348] " eregontp
2020-12-10 13:45 ` [ruby-core:101392] " daniel
@ 2020-12-10 13:58 ` marcandre-ruby-core
2020-12-10 14:58 ` [ruby-core:101394] " daniel
3 siblings, 0 replies; 5+ messages in thread
From: marcandre-ruby-core @ 2020-12-10 13:58 UTC (permalink / raw
To: ruby-core
Issue #17380 has been updated by marcandre (Marc-Andre Lafortune).
Dan0042 (Daniel DeLorme) wrote in #note-3:
> including a module is effectively a no-op
It isn't a no-op, as it does bring each method in the refinement, but those methods "live" outside of said refinement. See my example above where `:x.recurse(:y) # => :y (ok)`.
----------------------------------------
Feature #17380: Useful `include/prepend` in `refine`
https://bugs.ruby-lang.org/issues/17380#change-89153
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Currently, `prepend/include` within a `refine` block leads to a method not being to see itself, or others defined in the same module:
```ruby
module Code
def recurse(value = nil)
return value if value
recurse(42) # => NoMethodError!!!
end
end
module Extension
refine Object do
include Code
end
end
using Extension
:x.recurse(:y) # => :y (ok)
:x.recurse # => NoMethodError, was hoping for 42
```
I find this unintuitive and not useful.
The conclusion of the current situation from @shugo and others is ["I don't recommend module inclusion to define refined methods"](https://bugs.ruby-lang.org/issues/17374#note-9)
Could we change this situation so it can be recommended to use it?
What I believe would be more useful and is what I expected was that `include/prepend` within a `Module` would bring in the current methods in the Module, with the current refinements activated.
One use-case in particular is to publish libraries where one can give the option to the user to either:
- call `using GreatExtension` in each and every file that need it
- or `MyClass.prepend GreatExtension` once.
While [Jeremy Evans found a way to do it](https://bugs.ruby-lang.org/issues/17374#note-8), it remains challenging and unnatural.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:101394] [Ruby master Feature#17380] Useful `include/prepend` in `refine`
2020-12-09 4:31 [ruby-core:101326] [Ruby master Feature#17380] Useful `include/prepend` in `refine` marcandre-ruby-core
` (2 preceding siblings ...)
2020-12-10 13:58 ` [ruby-core:101393] " marcandre-ruby-core
@ 2020-12-10 14:58 ` daniel
3 siblings, 0 replies; 5+ messages in thread
From: daniel @ 2020-12-10 14:58 UTC (permalink / raw
To: ruby-core
Issue #17380 has been updated by Dan0042 (Daniel DeLorme).
marcandre (Marc-Andre Lafortune) wrote in #note-4:
> It isn't a no-op, as it does bring each method in the refinement, but those methods "live" outside of said refinement. See my example above where `:x.recurse(:y) # => :y (ok)`.
Yes, I understand that, but even if the methods are _technically_ in the refinement, if they are unreachable then _effectively_ it's the same as a no-op. Although as the example shows it's more like a "half-op"; the methods are reachable from the outside but not the inside.
----------------------------------------
Feature #17380: Useful `include/prepend` in `refine`
https://bugs.ruby-lang.org/issues/17380#change-89154
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Currently, `prepend/include` within a `refine` block leads to a method not being to see itself, or others defined in the same module:
```ruby
module Code
def recurse(value = nil)
return value if value
recurse(42) # => NoMethodError!!!
end
end
module Extension
refine Object do
include Code
end
end
using Extension
:x.recurse(:y) # => :y (ok)
:x.recurse # => NoMethodError, was hoping for 42
```
I find this unintuitive and not useful.
The conclusion of the current situation from @shugo and others is ["I don't recommend module inclusion to define refined methods"](https://bugs.ruby-lang.org/issues/17374#note-9)
Could we change this situation so it can be recommended to use it?
What I believe would be more useful and is what I expected was that `include/prepend` within a `Module` would bring in the current methods in the Module, with the current refinements activated.
One use-case in particular is to publish libraries where one can give the option to the user to either:
- call `using GreatExtension` in each and every file that need it
- or `MyClass.prepend GreatExtension` once.
While [Jeremy Evans found a way to do it](https://bugs.ruby-lang.org/issues/17374#note-8), it remains challenging and unnatural.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-12-10 14:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-09 4:31 [ruby-core:101326] [Ruby master Feature#17380] Useful `include/prepend` in `refine` marcandre-ruby-core
2020-12-09 18:43 ` [ruby-core:101348] " eregontp
2020-12-10 13:45 ` [ruby-core:101392] " daniel
2020-12-10 13:58 ` [ruby-core:101393] " marcandre-ruby-core
2020-12-10 14:58 ` [ruby-core:101394] " daniel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).