From: dblack@... Date: 2006-03-27T00:43:06+09:00 Subject: Re: Noob: use of the double colon Hi -- On Mon, 27 Mar 2006, Mark Volkmann wrote: > On 3/26/06, dblack@wobblini.net wrote: >> Hi -- >> >> On Sun, 26 Mar 2006, NuclearFusion wrote: >> >>> Hi, >>> >>> there seems to be more than one way to execute class methods. >>> I've seen the form (I use the classmethod new as an example): >>> newObject = Classname::new >>> but also >>> newObject = Classname.new >>> Bothe seem to work OK. >>> Is there a difference? If yes, what is the difference? >> >> They do both work. I've never understood why the :: exists for this >> purpose, since the . is the normal way of sending messages to objects >> and works perfectly well whether or not the receiver is a class. It's >> on my very short list of things I'd like to see removed from Ruby. > > Some might say this is another example of TIMTOWTDI. They'd be right, but that's the *Perl* slogan, not the Ruby slogan :-) (even though it's factually true of a number of things in Ruby) > However, like you, I'd like to see it changed to only use ".". > >>> Also I see :: being used in the context of modules. Can you tell me >>> about that as well? >> >> That's for looking up names of constants in nested scopes: >> >> module M >> X = 1 >> end >> >> puts M::X # 1 > > It seems to me that dots could be used for constant references too. > Maybe someone will point out a reason why this would complicate > parsing. I'd rather just have a message-sending operator (.) and a constant-lookup operator (::). These are completely different operations, and I don't think overlap in either direction is useful. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black