Actions
Bug #14012
closedNameError is raised when use class variables in Refinements
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
Backport:
Tags:
Description
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.
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?
Actions
Like0
Like0Like0Like0Like0