From: Hal Fulton Date: 2003-09-14T16:13:04+09:00 Subject: Re: Dot versus double-colon Gavin Sinclair wrote: >>First, why is it this way? > > File.open() is sending the message :open to object File. The same > cannot be said for the constant SEPARATOR. Certainly it could be said. In fact, there is no way to tell by looking at it whether it is in fact a method or a constant. And a constant could be viewed as a method that always returns the same value. Uniform access, you know. > :: makes sense for namespaces - as in constant resolution. It would > not bother me one bit should :: be deprecated for method calls. I'm accessing a value within an object. Sure, the value happens to be constant. So what? > >>By the way, for those who are wondering, this *is* possible: > > >> class File >> def self.SEPARATOR >> File::SEPARATOR >> end >> end > > >> File.SEPARATOR # "/" > > >>Even though it looks almost like recursion. Hmm, that raises >>the question of why/how this works. > > I'm sure you realise now. It's because you've defined a method :) You missed my point. Since the method File.SEPARATOR can be referred to by the syntax File::SEPARATOR, then how does the method know that it is not calling itself recursively? >>And another issue is: One *could* write a little module that, >>when included in a class, exposed all the class's constants in >>this way. Within five minutes I had it "almost" working. I'll >>bet someone in another timezone or with more caffeine could >>have it working in three. Anyone? > > > I'm happy for methods and constants to be accessed via different > mechanisms (message passing vs namespace resolution) and for those > mechanisms to be syntactically distinct. I see what you mean. But I say: Why should a constant be anything but a reader which happens always to return the same value? Hal