ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:76197] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
@ 2016-06-29 12:11 ` cardoso_tiago
  2016-06-29 12:12 ` [ruby-core:76198] " cardoso_tiago
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: cardoso_tiago @ 2016-06-29 12:11 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been reported by Tiago Cardoso.

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533

* Author: Tiago Cardoso
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Right now this isn't possible:

<pre>
module Extensions
def vegetables ; potatoe ; end
def potatoe ; "potatoe" ; end
end

module Refinary
refine String do
# this doesn't work
include Extensions
# this would work...
# def vegetables ; potatoe ; end
# def potatoe ; "potatoe" ; end
end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined methodvegetables' for "tomatoe":String
</pre>

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:76198] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
  2016-06-29 12:11 ` [ruby-core:76197] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines cardoso_tiago
@ 2016-06-29 12:12 ` cardoso_tiago
  2016-06-29 13:32 ` [ruby-core:76205] " futu.fata
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: cardoso_tiago @ 2016-06-29 12:12 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by Tiago Cardoso.


Sorry about the UI for the gist, apparently I don't know anymore how to properly declare code blocks in redmine...

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-59414

* Author: Tiago Cardoso
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Right now this isn't possible:

<pre>
module Extensions
def vegetables ; potatoe ; end
def potatoe ; "potatoe" ; end
end

module Refinary
refine String do
# this doesn't work
include Extensions
# this would work...
# def vegetables ; potatoe ; end
# def potatoe ; "potatoe" ; end
end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined methodvegetables' for "tomatoe":String
</pre>

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:76205] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
  2016-06-29 12:11 ` [ruby-core:76197] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines cardoso_tiago
  2016-06-29 12:12 ` [ruby-core:76198] " cardoso_tiago
@ 2016-06-29 13:32 ` futu.fata
  2016-06-29 13:34 ` [ruby-core:76206] " futu.fata
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: futu.fata @ 2016-06-29 13:32 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by Artem Khramov.

Description updated

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-59421

* Author: Tiago Cardoso
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:76206] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2016-06-29 13:32 ` [ruby-core:76205] " futu.fata
@ 2016-06-29 13:34 ` futu.fata
  2016-07-08  7:22 ` [ruby-core:76315] [Ruby trunk Feature#12533][Assigned] " shugo
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: futu.fata @ 2016-06-29 13:34 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by Artem Khramov.


Hi Tiago, the syntax is

\~\~\~ruby
your(code).goes here
\~\~\~



Sorry for offtop.

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-59422

* Author: Tiago Cardoso
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:76315] [Ruby trunk Feature#12533][Assigned] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2016-06-29 13:34 ` [ruby-core:76206] " futu.fata
@ 2016-07-08  7:22 ` shugo
  2017-06-13  0:27 ` [ruby-core:81655] [Ruby trunk Feature#12533] " shevegen
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: shugo @ 2016-07-08  7:22 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by Shugo Maeda.

Status changed from Open to Assigned
Assignee set to Yukihiro Matsumoto

Matz, what do you think of this?

Local rebinding may be worth considering, but there is a trade-off.

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-59551

* Author: Tiago Cardoso
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:81655] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2016-07-08  7:22 ` [ruby-core:76315] [Ruby trunk Feature#12533][Assigned] " shugo
@ 2017-06-13  0:27 ` shevegen
  2017-09-25  7:05 ` [ruby-core:82968] " duerst
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: shevegen @ 2017-06-13  0:27 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by shevegen (Robert A. Heiler).


Sorry for slight off-topic from me here - I wonder if refinements will be refined when ruby 3.x comes out ... :)

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-65352

* Author: chucke (Tiago Cardoso)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:82968] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2017-06-13  0:27 ` [ruby-core:81655] [Ruby trunk Feature#12533] " shevegen
@ 2017-09-25  7:05 ` duerst
  2017-09-25 12:28 ` [ruby-core:82991] " shyouhei
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: duerst @ 2017-09-25  7:05 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by duerst (Martin Dürst).


chucke (Tiago Cardoso) wrote:

> module Refinary

If possible, please change the spelling to "Refinery".

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-66871

* Author: chucke (Tiago Cardoso)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:82991] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2017-09-25  7:05 ` [ruby-core:82968] " duerst
@ 2017-09-25 12:28 ` shyouhei
  2017-09-26  8:34 ` [ruby-core:83019] " matz
  2017-10-06 11:59 ` [ruby-core:83159] " cardoso_tiago
  9 siblings, 0 replies; 10+ messages in thread
From: shyouhei @ 2017-09-25 12:28 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by shyouhei (Shyouhei Urabe).


We looked at this issue at a developer meeting today.

The OP's intension is clear.  We can describe how it works, but that seems to be different from how it _should_ work.  Matz was there at the discussion so he understands the situation.  I'm sure he's going to have some decision.

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-66899

* Author: chucke (Tiago Cardoso)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:83019] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2017-09-25 12:28 ` [ruby-core:82991] " shyouhei
@ 2017-09-26  8:34 ` matz
  2017-10-06 11:59 ` [ruby-core:83159] " cardoso_tiago
  9 siblings, 0 replies; 10+ messages in thread
From: matz @ 2017-09-26  8:34 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by matz (Yukihiro Matsumoto).


As you may know, `include` inserts the module in the inheritance hierarchy. In this case, `module Extensions` is inserted above `String` in the `using Refinary` scope. That means the lexical scope of `vegetables` and `potatoes` are different from the refined scope so that `potatoes` cannot be called from `vegetables` because the scope is not refined. The situation is a bit complex. Do you follow me?

In some other class extension proposals found in other languages (for example, ClassBox in Java), scopes of methods called from within ClassBox are also modified. This is called local rebinding. But we don't choose that because it has bigger side effects. We chose the safer side.

The issue is by `include` we might expect the features from the included module are available but in fact, they aren't due to the mechanism of `include` and refinements.

So I counter-propose a new feature, `Module#inject`. Unlike `include`, `inject` does not modify inheritance hierarchy. Instead, it copies attributes (constants, modules, and refinements) into the target class/module.


shevegen,
We have no concrete plan to refine the refinement. We are vaguely thinking about combining `require` and `using` in some way. Just idea.

Matz.


----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-66931

* Author: chucke (Tiago Cardoso)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:83159] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
       [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2017-09-26  8:34 ` [ruby-core:83019] " matz
@ 2017-10-06 11:59 ` cardoso_tiago
  9 siblings, 0 replies; 10+ messages in thread
From: cardoso_tiago @ 2017-10-06 11:59 UTC (permalink / raw)
  To: ruby-core

Issue #12533 has been updated by chucke (Tiago Cardoso).


How about redefining `#include` in the context of refine as what would be expected of the new `#inject` method? I get that the semantics of module inclusion differ in both context regarding inheritance hierarchy order, but I'm still thinking from the user perspective: "if I do it, what do I expect to happen?".

From this user perspective, I'd prefer an `#include` method which does what I expect, instead of yet another method (`#inject`) that I have to learn.

But there might be other implications. I'm fine with whichever proposal which makes refinements more usable for meta-programming. 

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-67095

* Author: chucke (Tiago Cardoso)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-10-06 11:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
2016-06-29 12:11 ` [ruby-core:76197] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines cardoso_tiago
2016-06-29 12:12 ` [ruby-core:76198] " cardoso_tiago
2016-06-29 13:32 ` [ruby-core:76205] " futu.fata
2016-06-29 13:34 ` [ruby-core:76206] " futu.fata
2016-07-08  7:22 ` [ruby-core:76315] [Ruby trunk Feature#12533][Assigned] " shugo
2017-06-13  0:27 ` [ruby-core:81655] [Ruby trunk Feature#12533] " shevegen
2017-09-25  7:05 ` [ruby-core:82968] " duerst
2017-09-25 12:28 ` [ruby-core:82991] " shyouhei
2017-09-26  8:34 ` [ruby-core:83019] " matz
2017-10-06 11:59 ` [ruby-core:83159] " cardoso_tiago

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).