From: ara.t.howard@... Date: 2006-03-27T01:41:51+09:00 Subject: Re: Noob: use of the double colon On Mon, 27 Mar 2006 dblack@wobblini.net wrote: > I honestly don't see any connection between the two techniques (:: and > suggestive variable names). c::meth doesn't communicate anything to me > about c. it does though - you know c __must__ be a module (classes being modules). > Even if it did, I'm not sold on the idea that it's necessary to have a > different message-sending operator for a particular class of objects. It > doesn't scale: you can come up with lots of variable names (my_class, etc.), > but you can't keep adding operators to make distinctions among receivers. > Nor is it necessarily vital in very many cases to make such distinctions. i can see that point of view. still, i like this: harp:~ > cat a.rb module A module B module C class D; end E = 42 def self::foo() 42 end end end end namespace = A::B::C p namespace::D p namespace::E p namespace::foo harp:~ > ruby a.rb A::B::C::D 42 42 and i think it's why '::' can call methods - though this is a w.a.g. > And when it's a matter of String.new vs. String::new, you already know it's > a class anyway :-) only sometimes though: module M class C end end def C(*a, &b) ::M::C::new(*a, &b) end C.new this is contrived, but String is a perfect example of this: both String() and String exist and certainly many libs export 'const methods'. all you really when a variable starts with [A-Z] is that it's a const. this happends quite a bit in my code because i always wrap up code into modules so i end up with things like this: module M module Logging end module Util end class A include Util include Logging end class B include Util include Logging end class C include Util include Logging end def self::new *a, &b C::new *a, &b end end where 'C' is sort of the 'default' or 'main' class in this set - so i provide a convenience method for the common ctor case. of course you can use '.new' here... i'm just pointing out that a lefthand side const may not be a class. regards. -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama