* [ruby-core:100491] [Ruby master Bug#14012] NameError is raised when use class variables in Refinements
[not found] <redmine.issue-14012.20171013113202.8753@ruby-lang.org>
@ 2020-10-22 5:00 ` shugo
2020-10-26 4:29 ` [ruby-core:100547] " matz
1 sibling, 0 replies; 2+ messages in thread
From: shugo @ 2020-10-22 5:00 UTC (permalink / raw)
To: ruby-core
Issue #14012 has been updated by shugo (Shugo Maeda).
I'm not against the change, if there is no implementation difficulty.
However, class variables are not accessible in class_eval either, and reflection APIs can be used as a workaround as you suggested, so the change may not be necessary.
----------------------------------------
Bug #14012: NameError is raised when use class variables in Refinements
https://bugs.ruby-lang.org/issues/14012#change-88110
* Author: joker1007 (Tomohiro Hashidate)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Sorry in advance if other ticket exists.
In a case, Reference to class variables raises unnatural NameError.
A class variable is defined in a module.
And include the module in "refine" block.
Refined method cannot use the class variable, and raises NameError.
Sample.
~~~ ruby
module FooMod
@@foo_mod1 = 1
def foo_mod1
p self.class.class_variable_get("@@foo_mod1")
end
end
module FooMod2
@@foo_mod2 = 1
def foo_mod2
p self.class.class_variable_get("@@foo_mod2")
end
end
class Foo
@@hoge = 1
include FooMod
def hoge1
p @@hoge
end
end
module Ext
refine Foo do
def hoge2
p self.class.class_variable_get("@@hoge")
end
include FooMod2
end
end
using Ext
Foo.new.hoge1 # => 1 OK
Foo.new.hoge2 # => 1 OK
Foo.new.foo_mod1 # => 1 OK
Foo.new.foo_mod2 # => uninitialized class variable @@foo_mod2 in Foo (NameError)
~~~
Is This behavior Refinements spec? or bug?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:100547] [Ruby master Bug#14012] NameError is raised when use class variables in Refinements
[not found] <redmine.issue-14012.20171013113202.8753@ruby-lang.org>
2020-10-22 5:00 ` [ruby-core:100491] [Ruby master Bug#14012] NameError is raised when use class variables in Refinements shugo
@ 2020-10-26 4:29 ` matz
1 sibling, 0 replies; 2+ messages in thread
From: matz @ 2020-10-26 4:29 UTC (permalink / raw)
To: ruby-core
Issue #14012 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Rejected
I officially reject this proposal. Class variables are no longer encouraged to use.
Matz.
----------------------------------------
Bug #14012: NameError is raised when use class variables in Refinements
https://bugs.ruby-lang.org/issues/14012#change-88174
* Author: joker1007 (Tomohiro Hashidate)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Sorry in advance if other ticket exists.
In a case, Reference to class variables raises unnatural NameError.
A class variable is defined in a module.
And include the module in "refine" block.
Refined method cannot use the class variable, and raises NameError.
Sample.
~~~ ruby
module FooMod
@@foo_mod1 = 1
def foo_mod1
p self.class.class_variable_get("@@foo_mod1")
end
end
module FooMod2
@@foo_mod2 = 1
def foo_mod2
p self.class.class_variable_get("@@foo_mod2")
end
end
class Foo
@@hoge = 1
include FooMod
def hoge1
p @@hoge
end
end
module Ext
refine Foo do
def hoge2
p self.class.class_variable_get("@@hoge")
end
include FooMod2
end
end
using Ext
Foo.new.hoge1 # => 1 OK
Foo.new.hoge2 # => 1 OK
Foo.new.foo_mod1 # => 1 OK
Foo.new.foo_mod2 # => uninitialized class variable @@foo_mod2 in Foo (NameError)
~~~
Is This behavior Refinements spec? or bug?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-26 4:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-14012.20171013113202.8753@ruby-lang.org>
2020-10-22 5:00 ` [ruby-core:100491] [Ruby master Bug#14012] NameError is raised when use class variables in Refinements shugo
2020-10-26 4:29 ` [ruby-core:100547] " matz
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).