Is there my L constants?
module M
class Z
class << self
L = "foo"
end
end
end
=> M::Z::L
=> NameError: uninitialized constant M::Z::L
=> M::Z.constants
=> []
module B
class N
X = "bar"
end
end
=> B::N::X
=> "bar"
=> B::N.constants
=> [:X]
I read this but I do not understand.
You need to do as :
module M
class Z
class << self
L = "foo"
end
end
end
M::Z.singleton_class::L # => "foo"
L is defined inside the singleton class of Z.
"L" is stored in the set of constants of the singleton class of M::Z, You may call it S for now. M::Z::L it actually is searching this constant L, in the constant table of M::Z and its ancestors. since none of them is S, the look-up fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With