* [ruby-core:71862] [Ruby trunk - Bug #11779] [Open] Mudule#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
@ 2015-12-06 21:40 ` alxtskrnk
2015-12-07 3:52 ` [ruby-core:71864] [Ruby trunk - Bug #11779] Module#using " alxtskrnk
` (29 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-06 21:40 UTC (permalink / raw
To: ruby-core
Issue #11779 has been reported by bug hit.
----------------------------------------
Bug #11779: Mudule#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779
* Author: bug hit
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71864] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
2015-12-06 21:40 ` [ruby-core:71862] [Ruby trunk - Bug #11779] [Open] Mudule#using does not make sense as a method alxtskrnk
@ 2015-12-07 3:52 ` alxtskrnk
2015-12-07 6:52 ` [ruby-core:71869] [Ruby trunk - Bug #11779] [Feedback] " matz
` (28 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-07 3:52 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Subject changed from Mudule#using does not make sense as a method to Module#using does not make sense as a method
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55265
* Author: bug hit
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71869] [Ruby trunk - Bug #11779] [Feedback] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
2015-12-06 21:40 ` [ruby-core:71862] [Ruby trunk - Bug #11779] [Open] Mudule#using does not make sense as a method alxtskrnk
2015-12-07 3:52 ` [ruby-core:71864] [Ruby trunk - Bug #11779] Module#using " alxtskrnk
@ 2015-12-07 6:52 ` matz
2015-12-07 16:09 ` [ruby-core:71912] [Ruby trunk - Bug #11779] " alxtskrnk
` (27 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: matz @ 2015-12-07 6:52 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Yukihiro Matsumoto.
Status changed from Open to Feedback
Can elaborate what do you want if `using` should not be a method.
Considering a new keyword would break existing code, I don't think it's a good idea.
Matz.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55271
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71912] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (2 preceding siblings ...)
2015-12-07 6:52 ` [ruby-core:71869] [Ruby trunk - Bug #11779] [Feedback] " matz
@ 2015-12-07 16:09 ` alxtskrnk
2015-12-07 17:00 ` [ruby-core:71913] " matz
` (26 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-07 16:09 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Yukihiro Matsumoto wrote:
> Can elaborate what do you want if `using` should not be a method.
> Considering a new keyword would break existing code, I don't think it's a good idea.
>
I don't know what possibilities there are, it just struck me that it was not behaving at all as a method, methods affect their dynamically scoped receiver, `using` affects the lexically scoped currently open module. So a keyword, if it were possible, would be more appropriate. Don't know what else it could be.
If it stays a method, what about #3
```ruby
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
```
what should happen here?
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55318
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71913] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (3 preceding siblings ...)
2015-12-07 16:09 ` [ruby-core:71912] [Ruby trunk - Bug #11779] " alxtskrnk
@ 2015-12-07 17:00 ` matz
2015-12-07 17:21 ` [ruby-core:71917] " alxtskrnk
` (25 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: matz @ 2015-12-07 17:00 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Yukihiro Matsumoto.
Providing a feature by a method does not imply dynamic scoping, for example, Module#private etc. work in lexical scope.
Matz.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55319
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71917] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (4 preceding siblings ...)
2015-12-07 17:00 ` [ruby-core:71913] " matz
@ 2015-12-07 17:21 ` alxtskrnk
2015-12-07 17:43 ` [ruby-core:71918] " alxtskrnk
` (24 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-07 17:21 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Yukihiro Matsumoto wrote:
> Providing a feature by a method does not imply dynamic scoping, for example, Module#private etc. work in lexical scope.
>
> Matz.
Well, since it's an established pattern, one has to just accept it. It does seem unintuitive to me that method calls, which are dynamically bound to self, are actually operating on the currently open class
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55323
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71918] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (5 preceding siblings ...)
2015-12-07 17:21 ` [ruby-core:71917] " alxtskrnk
@ 2015-12-07 17:43 ` alxtskrnk
2015-12-09 1:17 ` [ruby-core:71963] " shugo
` (23 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-07 17:43 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Yukihiro Matsumoto wrote:
> Providing a feature by a method does not imply dynamic scoping, for example, Module#private etc. work in lexical scope.
>
> Matz.
actually `private` is more dynamic than `using`, here's an example of private working not on the currently open class but on the dynamically bound default definee:
```ruby
Class1.class_eval do
private
def meth1
end
end
Class1.new.meth1 # private method `meth1' called
```
whereas using is not affected by `self` or "default definee"
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
#using Refinement
def self.refined?
''.refined? rescue false
end
end
Foo.module_eval do
using Refinement
p refined? # false
end
p Foo.refined? #false
```
Is the above behavior correct? Instead of doing nothing, should this use of `using` produce an error or perhaps work inside the `module_eval` block
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55324
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71963] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (6 preceding siblings ...)
2015-12-07 17:43 ` [ruby-core:71918] " alxtskrnk
@ 2015-12-09 1:17 ` shugo
2015-12-09 1:31 ` [ruby-core:71964] " alxtskrnk
` (22 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-09 1:17 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
Yukihiro Matsumoto wrote:
> Providing a feature by a method does not imply dynamic scoping, for example, Module#private etc. work in lexical scope.
However, it might be better to provide Kernel#using instead of main.using and Module#using,
because the behavior does not depend on the receiver.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55372
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71964] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (7 preceding siblings ...)
2015-12-09 1:17 ` [ruby-core:71963] " shugo
@ 2015-12-09 1:31 ` alxtskrnk
2015-12-09 1:41 ` [ruby-core:71965] " nobu
` (21 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-09 1:31 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Please explain the following behavior of `using`:
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
Foo.module_eval do
using Refinement
p refined? # false
end
p Foo.refined? #false
```
If this is a noop, as it seems to be, then it should not be allowed
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55373
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71965] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (8 preceding siblings ...)
2015-12-09 1:31 ` [ruby-core:71964] " alxtskrnk
@ 2015-12-09 1:41 ` nobu
2015-12-09 1:51 ` [ruby-core:71966] " alxtskrnk
` (20 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: nobu @ 2015-12-09 1:41 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Nobuyoshi Nakada.
It is not a noop, just you don't use the refined method there.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55374
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71966] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (9 preceding siblings ...)
2015-12-09 1:41 ` [ruby-core:71965] " nobu
@ 2015-12-09 1:51 ` alxtskrnk
2015-12-09 1:55 ` [ruby-core:71967] " alxtskrnk
` (19 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-09 1:51 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Nobuyoshi Nakada wrote:
> It is not a noop, just you don't use the refined method there.
Where "there"? Where should I use the refined method to see the effect of that using call?
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55375
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71967] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (10 preceding siblings ...)
2015-12-09 1:51 ` [ruby-core:71966] " alxtskrnk
@ 2015-12-09 1:55 ` alxtskrnk
2015-12-09 2:00 ` [ruby-core:71968] " alxtskrnk
` (18 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-09 1:55 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
bug hit wrote:
> Nobuyoshi Nakada wrote:
> > It is not a noop, just you don't use the refined method there.
>
> Where "there"? Where should I use the refined method to see the effect of that using call?
ok got it, thanks
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
Foo.module_eval do
using Refinement
p((''.refined? rescue false)) #true
end
```
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55376
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71968] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (11 preceding siblings ...)
2015-12-09 1:55 ` [ruby-core:71967] " alxtskrnk
@ 2015-12-09 2:00 ` alxtskrnk
2015-12-09 5:02 ` [ruby-core:71971] " shugo
` (17 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-09 2:00 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
bug hit wrote:
> bug hit wrote:
> > Nobuyoshi Nakada wrote:
> > > It is not a noop, just you don't use the refined method there.
> >
> > Where "there"? Where should I use the refined method to see the effect of that using call?
>
> ok got it, thanks
>
> ```ruby
> module Refinement
> refine String do
> def refined?
> true
> end
> end
> end
>
> module Foo
> def self.refined?
> ''.refined? rescue false
> end
> end
>
> Foo.module_eval do
> using Refinement
> p((''.refined? rescue false)) #true
> end
> ```
so if `using` inside module_eval is intended to work then invoking such a module_eval from a method should also work (it raises Module#using is not permitted in methods):
```Ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
def self.foo
module_eval do
using Refinement # Module#using is not permitted in methods
p((''.refined? rescue false))
end
end
foo
end
```
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55377
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71971] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (12 preceding siblings ...)
2015-12-09 2:00 ` [ruby-core:71968] " alxtskrnk
@ 2015-12-09 5:02 ` shugo
2015-12-09 5:17 ` [ruby-core:71974] " alxtskrnk
` (16 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-09 5:02 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
bug hit wrote:
> so if `using` inside module_eval is intended to work, then invoking such a module_eval from a method should also work (it raises Module#using is not permitted in methods):
Module#using is not intented to work as you expect.
Instead, the following extension of *_eval might be considerable:
```
module_eval(using: Refinement) {
...
}
```
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55380
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71974] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (13 preceding siblings ...)
2015-12-09 5:02 ` [ruby-core:71971] " shugo
@ 2015-12-09 5:17 ` alxtskrnk
2015-12-09 5:29 ` [ruby-core:71975] " shugo
` (15 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-09 5:17 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Shugo Maeda wrote:
> bug hit wrote:
> > so if `using` inside module_eval is intended to work, then invoking such a module_eval from a method should also work (it raises Module#using is not permitted in methods):
>
> Module#using is not intented to work as you expect.
>
This wasn't really my expectation, it was nobu's explanation (It is not a noop, just you don't use the refined method there), which I confirmed.
"using" called from a module_eval block activates the refinement in the block
Are you saying that's a bug?
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55383
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71975] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (14 preceding siblings ...)
2015-12-09 5:17 ` [ruby-core:71974] " alxtskrnk
@ 2015-12-09 5:29 ` shugo
2015-12-09 5:40 ` [ruby-core:71981] " alxtskrnk
` (14 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-09 5:29 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
bug hit wrote:
> Shugo Maeda wrote:
> > bug hit wrote:
> > > so if `using` inside module_eval is intended to work, then invoking such a module_eval from a method should also work (it raises Module#using is not permitted in methods):
> >
> > Module#using is not intented to work as you expect.
> >
>
> This wasn't really my expectation, it was nobu's explanation (It is not a noop, just you don't use the refined method there), which I confirmed.
>
> "using" called from a module_eval block activates the refinement in the block
>
> Are you saying that's a bug?
Nobu didn't explain that Module#using should work in methods.
Module#using is designed not for such dynamic use.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55384
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71981] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (15 preceding siblings ...)
2015-12-09 5:29 ` [ruby-core:71975] " shugo
@ 2015-12-09 5:40 ` alxtskrnk
2015-12-09 6:24 ` [ruby-core:71985] " shugo
` (13 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-09 5:40 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Shugo Maeda wrote:
> bug hit wrote:
> > Shugo Maeda wrote:
> > > bug hit wrote:
> > > > so if `using` inside module_eval is intended to work, then invoking such a module_eval from a method should also work (it raises Module#using is not permitted in methods):
> > >
> > > Module#using is not intented to work as you expect.
> > >
> >
> > This wasn't really my expectation, it was nobu's explanation (It is not a noop, just you don't use the refined method there), which I confirmed.
> >
> > "using" called from a module_eval block activates the refinement in the block
> >
> > Are you saying that's a bug?
>
> Nobu didn't explain that Module#using should work in methods.
> Module#using is designed not for such dynamic use.
Note that when #using is called in a module eval_block, it's effect is confined to the body of the block. So why should it matter if module_eval is called from a method or top level or from another module/class? Regardless of where it's called, #using inside it works the same.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55389
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:71985] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (16 preceding siblings ...)
2015-12-09 5:40 ` [ruby-core:71981] " alxtskrnk
@ 2015-12-09 6:24 ` shugo
2015-12-09 16:37 ` [ruby-core:72004] " alxtskrnk
` (12 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-09 6:24 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
bug hit wrote:
> > Nobu didn't explain that Module#using should work in methods.
> > Module#using is designed not for such dynamic use.
>
> Note that when #using is called in a module_eval block, its effect is confined to the body of the block. So why should it matter if module_eval is called from a method or top level or from another module/class? ~~Regardless of where it's called, #using inside it works the same.~~ The call site does not influence what #using does nor is influenced by it.
Because refinement activation should be as static as possible.
It might be better to prohibit Module#using in module_eval.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55394
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72004] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (17 preceding siblings ...)
2015-12-09 6:24 ` [ruby-core:71985] " shugo
@ 2015-12-09 16:37 ` alxtskrnk
2015-12-10 3:58 ` [ruby-core:72021] " shugo
` (11 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-09 16:37 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Shugo Maeda wrote:
> bug hit wrote:
> > > Nobu didn't explain that Module#using should work in methods.
> > > Module#using is designed not for such dynamic use.
> >
> > Note that when #using is called in a module_eval block, its effect is confined to the body of the block. So why should it matter if module_eval is called from a method or top level or from another module/class? ~~Regardless of where it's called, #using inside it works the same.~~ The call site does not influence what #using does nor is influenced by it.
>
> Because refinement activation should be as static as possible.
> It might be better to prohibit Module#using in module_eval.
Perhaps, since you can apply the refinement outside the module_eval block which will also affect the block:
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
end
module Bar
using Refinement
Foo.module_eval do
p((''.refined? rescue false))
end
end
```
so a #using in module_eval is only useful if you want the refinement confined to the block. There might be uses for that, not sure.
But if this functionality remains, it should work wherever module_eval is invoked.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55413
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72021] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (18 preceding siblings ...)
2015-12-09 16:37 ` [ruby-core:72004] " alxtskrnk
@ 2015-12-10 3:58 ` shugo
2015-12-10 7:01 ` [ruby-core:72024] " alxtskrnk
` (10 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-10 3:58 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
bug hit wrote:
> so a #using in module_eval is only useful if you want the refinement confined to the block. There might be uses for that, not sure.
Yes, it's the current intended behavior.
> But if this functionality remains, it should work wherever module_eval is invoked.
Such dynamic extension of refinements should be discussed in a different ticket as a new feature.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55431
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72024] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (19 preceding siblings ...)
2015-12-10 3:58 ` [ruby-core:72021] " shugo
@ 2015-12-10 7:01 ` alxtskrnk
2015-12-10 7:07 ` [ruby-core:72025] " shugo
` (9 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-10 7:01 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Shugo Maeda wrote:
> ...
> Because refinement activation should be as static as possible.
> ...
ruby is too dynamic a language to have a clear distinction between what you're calling "static" and "dynamic" You are labeling class bodies as "static" and methods "dynamic" but a class body is executable ruby and can be invoked by methods, so the current restriction on module_eval can be overcome with relative ease:
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
end
module Bar
def self.mod_eval_with_refine(mod)
singleton_class.instance_variable_set :@mod, mod
class << self
@mod.module_eval do
using Refinement
p((''.refined? rescue false))
end
end
end
end
Bar.mod_eval_with_refine(Foo)
```
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55436
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72025] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (20 preceding siblings ...)
2015-12-10 7:01 ` [ruby-core:72024] " alxtskrnk
@ 2015-12-10 7:07 ` shugo
2015-12-10 7:17 ` [ruby-core:72026] " alxtskrnk
` (8 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-10 7:07 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
bug hit wrote:
> Shugo Maeda wrote:
> > ...
> > Because refinement activation should be as static as possible.
> > ...
>
> ruby is too dynamic a language to have a clear distinction between what you're calling "static" and "dynamic" You are labeling class bodies as "static" and methods "dynamic" but a class body is executable ruby and can be invoked by methods, so the current restriction on module_eval can be overcome with relative ease:
Methods are expected to be invoked more than once, so there's a significant difference from class bodies.
That's why static features like constant assignments are prohibited in method definitions.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55437
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72026] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (21 preceding siblings ...)
2015-12-10 7:07 ` [ruby-core:72025] " shugo
@ 2015-12-10 7:17 ` alxtskrnk
2015-12-10 9:29 ` [ruby-core:72027] " shugo
` (7 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-10 7:17 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Shugo Maeda wrote:
> bug hit wrote:
> > Shugo Maeda wrote:
> > > ...
> > > Because refinement activation should be as static as possible.
> > > ...
> >
> > ruby is too dynamic a language to have a clear distinction between what you're calling "static" and "dynamic" You are labeling class bodies as "static" and methods "dynamic" but a class body is executable ruby and can be invoked by methods, so the current restriction on module_eval can be overcome with relative ease:
>
> Methods are expected to be invoked more than once, so there's a significant difference from class bodies.
> That's why static features like constant assignments are prohibited in method definitions.
Did you see the example in my previous post? Effectively there is no prohibition against module_eval with #using in methods, because you can open a class in a method and call module_eval from there.
Also you are forgetting a category of methods (class macros) that help initialize/modify classes through meta-programming and are meant to be called once in the class body. Such methods should be able to do whatever the class body can do.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55438
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72027] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (22 preceding siblings ...)
2015-12-10 7:17 ` [ruby-core:72026] " alxtskrnk
@ 2015-12-10 9:29 ` shugo
2015-12-10 16:12 ` [ruby-core:72035] " alxtskrnk
` (6 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-10 9:29 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
bug hit wrote:
> > > ruby is too dynamic a language to have a clear distinction between what you're calling "static" and "dynamic" You are labeling class bodies as "static" and methods "dynamic" but a class body is executable ruby and can be invoked by methods, so the current restriction on module_eval can be overcome with relative ease:
> >
> > Methods are expected to be invoked more than once, so there's a significant difference from class bodies.
> > That's why static features like constant assignments are prohibited in method definitions.
>
> Did you see the example in my previous post? Effectively there is no prohibition against module_eval with #using in methods, because you can open a class in a method and call module_eval from there.
Other features have similar loopholes (e.g., constants can be assigned in methods by eval,
private methods can be called by Kernel#send, etc.), but it doesn't mean such restriction
is meaningless, because it can express the intention.
> Also you are forgetting a category of methods (class macros) that help initialize/modify classes through meta-programming and are meant to be called once in the class body. Such methods should be able to do whatever the class body can do.
Perhaps, perhaps not. I depends on what the phrase "whatever the class body can do" mean.
For exmaple, such methods should be able to define constants in a class, but need not to
be able to define constants in the same way as in a class body.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55439
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72035] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (23 preceding siblings ...)
2015-12-10 9:29 ` [ruby-core:72027] " shugo
@ 2015-12-10 16:12 ` alxtskrnk
2015-12-12 4:35 ` [ruby-core:72074] " shugo
` (5 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2015-12-10 16:12 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bug hit.
Shugo Maeda wrote:
> bug hit wrote:
> > > > ruby is too dynamic a language to have a clear distinction between what you're calling "static" and "dynamic" You are labeling class bodies as "static" and methods "dynamic" but a class body is executable ruby and can be invoked by methods, so the current restriction on module_eval can be overcome with relative ease:
> > >
> > > Methods are expected to be invoked more than once, so there's a significant difference from class bodies.
> > > That's why static features like constant assignments are prohibited in method definitions.
> >
> > Did you see the example in my previous post? Effectively there is no prohibition against module_eval with #using in methods, because you can open a class in a method and call module_eval from there.
>
> Other features have similar loopholes (e.g., constants can be assigned in methods by eval,
> private methods can be called by Kernel#send, etc.), but it doesn't mean such restriction
> is meaningless, because it can express the intention.
>
> > Also you are forgetting a category of methods (class macros) that help initialize/modify classes through meta-programming and are meant to be called once in the class body. Such methods should be able to do whatever the class body can do.
>
> Perhaps, perhaps not. I depends on what the phrase "whatever the class body can do" mean.
> For exmaple, such methods should be able to define constants in a class, but need not to
> be able to define constants in the same way as in a class body.
Of course I don't mean in the same exact way, meta-programming is different than native syntax. However the question of "how" does not apply here, because you are arguing that it should be forbidden (not different), and I'm saying that if a class body can call a module_eval with using, then a class macro method should be able to, as well.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55446
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72074] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (24 preceding siblings ...)
2015-12-10 16:12 ` [ruby-core:72035] " alxtskrnk
@ 2015-12-12 4:35 ` shugo
2015-12-12 6:06 ` [ruby-core:72075] " shugo
` (4 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-12 4:35 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
Assignee set to Yukihiro Matsumoto
bug hit wrote:
> > Perhaps, perhaps not. I depends on what the phrase "whatever the class body can do" mean.
> > For exmaple, such methods should be able to define constants in a class, but need not to
> > be able to define constants in the same way as in a class body.
>
> Of course I don't mean in the same exact way, meta-programming is different than native syntax. However the question of "how" does not apply here, because you are arguing that it should be forbidden (not different), and I'm saying that if a class body can call a module_eval with using, then a class macro method should be able to, as well.
As I stated before, it might be better to introduce Kernel#using, which ignores module_eval blocks as constant lookup do.
```ruby
module Foo
refine String do
def foo
puts "foo"
end
end
end
module Bar
end
module Baz
Bar.module_eval do
using Foo
"".foo #=> foo
end
"".foo #=> foo
end
"".foo #=> error
```
I'd like to hear Matz's opinion.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55486
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:72075] [Ruby trunk - Bug #11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (25 preceding siblings ...)
2015-12-12 4:35 ` [ruby-core:72074] " shugo
@ 2015-12-12 6:06 ` shugo
2017-07-07 17:07 ` [ruby-core:81960] [Ruby trunk Bug#11779] " alxtskrnk
` (3 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: shugo @ 2015-12-12 6:06 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by Shugo Maeda.
Shugo Maeda wrote:
> As I stated before, it might be better to introduce Kernel#using, which ignores module_eval blocks as constant lookup do.
Or it might be better to prohibit using in blocks.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-55488
* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:81960] [Ruby trunk Bug#11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (26 preceding siblings ...)
2015-12-12 6:06 ` [ruby-core:72075] " shugo
@ 2017-07-07 17:07 ` alxtskrnk
2017-07-08 2:10 ` [ruby-core:81965] " nobu
` (2 subsequent siblings)
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2017-07-07 17:07 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bughit (bug hit).
matz (Yukihiro Matsumoto) wrote:
> Providing a feature by a method does not imply dynamic scoping, for example, Module#private etc. work in lexical scope.
I didn't think about Module#private too deeply at the time, but recently was prompted by something, and Module#private is not lexical
```ruby
module Mod1
class Class1
end
def self.lookup_class
Class1
end
lookup_class.class_eval do
def foo1
self
end
private
def foo2
self
end
end
lookup_class.instance_eval do
define_method :bar1 do
self
end
def bar1
self
end
private
def bar2
self
end
define_method :bar2 do
self
end
end
c1 = Class1.new
c1.foo1.foo2 rescue puts $!.inspect
Class1.bar1.bar2 rescue puts $!.inspect
c1.bar1.bar2 rescue puts $!.inspect
end
```
it affects the dynamically scoped default definee, which though dynamic does not necessarily match the receiver.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-65683
* Author: bughit (bug hit)
* Status: Feedback
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:81965] [Ruby trunk Bug#11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (27 preceding siblings ...)
2017-07-07 17:07 ` [ruby-core:81960] [Ruby trunk Bug#11779] " alxtskrnk
@ 2017-07-08 2:10 ` nobu
2017-07-08 3:28 ` [ruby-core:81967] " alxtskrnk
2018-04-26 11:05 ` [ruby-core:86700] " alex.wayfer
30 siblings, 0 replies; 31+ messages in thread
From: nobu @ 2017-07-08 2:10 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by nobu (Nobuyoshi Nakada).
Seems that your "dynamic" and "lexical" words differ from ours.
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-65688
* Author: bughit (bug hit)
* Status: Feedback
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:81967] [Ruby trunk Bug#11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (28 preceding siblings ...)
2017-07-08 2:10 ` [ruby-core:81965] " nobu
@ 2017-07-08 3:28 ` alxtskrnk
2018-04-26 11:05 ` [ruby-core:86700] " alex.wayfer
30 siblings, 0 replies; 31+ messages in thread
From: alxtskrnk @ 2017-07-08 3:28 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by bughit (bug hit).
nobu (Nobuyoshi Nakada) wrote:
> Seems that your "dynamic" and "lexical" words differ from ours.
I was using "dynamic" to mean that its dynamically "bound" (applies) to the default definee at the point of invocation, not the lexically determined currently open class. It's true that the receiver does not matter at all (I initially thought it had to self):
```ruby
module Mod1
class Class1
end
def self.lookup_class
Class1
end
lookup_class.class_eval do
def foo1
self
end
Module.new.send(:private)
def foo2
self
end
end
c1 = Class1.new
c1.foo1.foo2 rescue puts $!.inspect
end
```
Please clarify how you're using dynamic vs lexical?
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-65691
* Author: bughit (bug hit)
* Status: Feedback
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
* [ruby-core:86700] [Ruby trunk Bug#11779] Module#using does not make sense as a method
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
` (29 preceding siblings ...)
2017-07-08 3:28 ` [ruby-core:81967] " alxtskrnk
@ 2018-04-26 11:05 ` alex.wayfer
30 siblings, 0 replies; 31+ messages in thread
From: alex.wayfer @ 2018-04-26 11:05 UTC (permalink / raw
To: ruby-core
Issue #11779 has been updated by AlexWayfer (Alexander Popov).
From RSpec:
~~~ ruby
let(:test_class) do
Class.new(described_class) do
private
using SomeRefiningModule # => RuntimeError: Module#using is not permitted in methods
def foo
end
end
end
~~~
----------------------------------------
Bug #11779: Module#using does not make sense as a method
https://bugs.ruby-lang.org/issues/11779#change-71658
* Author: bughit (bug hit)
* Status: Feedback
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
* ruby -v: 2.2.3
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
1. it can't be called from another method
2. the receiver must be self
3. since refinements are lexically scoped the self receiver must match the currently open class
#3 is particularly curious
```ruby
module Refinement
refine String do
def refined?
true
end
end
end
module Foo
def self.refined?
''.refined? rescue false
end
end
module Bar
def self.refined?
''.refined? rescue false
end
Foo.module_eval do
using Refinement
end
end
p Foo.refined? #false
```
The module_eval `#using` call does not raise (it's not from a method and the receiver is self), but evidently because currently open class does not match self, it does not do anything. So it should at least raise.
So `#using`, though a method, does not function as a method, which is misleading.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 31+ messages in thread
end of thread, other threads:[~2018-04-26 11:05 UTC | newest]
Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-11779.20151206214013@ruby-lang.org>
2015-12-06 21:40 ` [ruby-core:71862] [Ruby trunk - Bug #11779] [Open] Mudule#using does not make sense as a method alxtskrnk
2015-12-07 3:52 ` [ruby-core:71864] [Ruby trunk - Bug #11779] Module#using " alxtskrnk
2015-12-07 6:52 ` [ruby-core:71869] [Ruby trunk - Bug #11779] [Feedback] " matz
2015-12-07 16:09 ` [ruby-core:71912] [Ruby trunk - Bug #11779] " alxtskrnk
2015-12-07 17:00 ` [ruby-core:71913] " matz
2015-12-07 17:21 ` [ruby-core:71917] " alxtskrnk
2015-12-07 17:43 ` [ruby-core:71918] " alxtskrnk
2015-12-09 1:17 ` [ruby-core:71963] " shugo
2015-12-09 1:31 ` [ruby-core:71964] " alxtskrnk
2015-12-09 1:41 ` [ruby-core:71965] " nobu
2015-12-09 1:51 ` [ruby-core:71966] " alxtskrnk
2015-12-09 1:55 ` [ruby-core:71967] " alxtskrnk
2015-12-09 2:00 ` [ruby-core:71968] " alxtskrnk
2015-12-09 5:02 ` [ruby-core:71971] " shugo
2015-12-09 5:17 ` [ruby-core:71974] " alxtskrnk
2015-12-09 5:29 ` [ruby-core:71975] " shugo
2015-12-09 5:40 ` [ruby-core:71981] " alxtskrnk
2015-12-09 6:24 ` [ruby-core:71985] " shugo
2015-12-09 16:37 ` [ruby-core:72004] " alxtskrnk
2015-12-10 3:58 ` [ruby-core:72021] " shugo
2015-12-10 7:01 ` [ruby-core:72024] " alxtskrnk
2015-12-10 7:07 ` [ruby-core:72025] " shugo
2015-12-10 7:17 ` [ruby-core:72026] " alxtskrnk
2015-12-10 9:29 ` [ruby-core:72027] " shugo
2015-12-10 16:12 ` [ruby-core:72035] " alxtskrnk
2015-12-12 4:35 ` [ruby-core:72074] " shugo
2015-12-12 6:06 ` [ruby-core:72075] " shugo
2017-07-07 17:07 ` [ruby-core:81960] [Ruby trunk Bug#11779] " alxtskrnk
2017-07-08 2:10 ` [ruby-core:81965] " nobu
2017-07-08 3:28 ` [ruby-core:81967] " alxtskrnk
2018-04-26 11:05 ` [ruby-core:86700] " alex.wayfer
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).