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.