module Module1
class Base1
class << self
attr_accessor :attr1, :attr2
def configure
yield(self) if block_given?
end
end
end
end
module Module1
class Child1 < Base1
def self.some_method1
#... some stuff
"#{attr1}_123" #for some reason attr1 is nil
end
end
end
Module1::Base1.configure do |item|
item.method1 = "43243243"
item.method2 = "fdsfdsfd"
end
data1 = Module1::Child1.some_method1 #it doesn't return what I expect
由于某种原因 attr1
, inChild1#some_method1
与它的价值nil
不同。Module1::Base1.method1
我想知道为什么以及我应该怎么做才能摆脱它?