From: Gavin Sinclair Date: 2004-06-05T21:35:29+09:00 Subject: Re: class A::B verses module A ; class B On Saturday, June 5, 2004, 7:58:48 PM, Kent wrote: > Jeff Mitchell wrote: >> module A >> FOO = 99 >> end >> >> module A >> class B >> puts "FOO is #{FOO}" # => "FOO is 99" >> end >> end >> >> class A::B >> puts "FOO is #{FOO}" # error >> end >> >> Comments? I assumed the two forms were equivalent until I ran into >> this. Is there a reason they should be different? I prefer the >> second form, if only to save some indentation space. > I'm on the "hope it's a feature" side on this one. It means you have to > explicitly open namespaces you want to use, and the A::B shortcut > notation only opens the last namespace. I dislike the behaviour displayed above. But your explanation for it is quite reasonable. > Some of this has already been discussed in the thread > "Nested class/module namespace", see [rubytalk:78843] for Matz' answer. > http://rubytalk.com/78843 I think in Ruby 2.0 there will be a change in the way constants are resolved (see Matz's slides, wherever they lay). That would most likely mean that how you arrived at a particular namespace is irrelevant. Gavin