From: Stefano Crocco Date: 2007-08-23T21:56:47+09:00 Subject: Re: What is the difference between :, ::, . ? Alle gioved� 23 agosto 2007, Gabriel Dragffy ha scritto: > Hi, I'm still confused when to use :: or : or . to access namespaces > and methods. Could someone please tell me concisely when each should > be used? > > Many thanks > > Gabriel * The dot (.) is used to access a method of an object (remember that class/module methods are simply instance methods of the class object). For example: "a string".capitalize 1.ceil [1, 2, 3].uniq Regexp.escape * The double colon (::) operator is used to access a constant contained in a module or class (remember that classes and modules are usually stored in constants). It can also be used to access class/module methods (but I think this is not much used) Regexp::EXTENDED #a constant in the Regexp class Enumerable::Enumerator #a class in the Enumerable modules File::exist? #a class method of the File class * The colon (:) operator has nothing to do with namespaces. Its only use, as far as I remember, is in the ternary operator ? a ? b : c which is equivalent to if a then b else c end Besides, a colon is also used in Symbol literals: :a_symbol which is the same as 'a_symbol'.to_sym. I hope this helps Stefano