G
Gavin Sinclair
Folks,
I know this sort of thing has been talked about before, but that's not
going to stop me
module M
X = 5
class C
def foo
puts "X = #{X}"
end
end
end
class M::C
def bar
puts "X = #{X}"
end
end
M::C.new.foo # X = 5
M::C.new.bar # NameError: uninitialized constant M::C::X
The problem is that when you use 'class M::C' to open a class, you
can't access constants declared in M, whereas if you use 'module M;
class C', you can.
1) Why is this?
2) Is is an intentional behaviour of Ruby?
I feel fairly confident that the new constant resolution rules will
sort this out, but I'm wondering why it can't be made to work now.
ruby 1.8.1 (2004-01-08) [i386-cygwin]
Gavin
I know this sort of thing has been talked about before, but that's not
going to stop me
module M
X = 5
class C
def foo
puts "X = #{X}"
end
end
end
class M::C
def bar
puts "X = #{X}"
end
end
M::C.new.foo # X = 5
M::C.new.bar # NameError: uninitialized constant M::C::X
The problem is that when you use 'class M::C' to open a class, you
can't access constants declared in M, whereas if you use 'module M;
class C', you can.
1) Why is this?
2) Is is an intentional behaviour of Ruby?
I feel fairly confident that the new constant resolution rules will
sort this out, but I'm wondering why it can't be made to work now.
ruby 1.8.1 (2004-01-08) [i386-cygwin]
Gavin