Hi -- On Wed, 26 Apr 2006, dblack / wobblini.net wrote: > Hi -- > > On Wed, 26 Apr 2006, malamute jute wrote: > >> newb here. >> >> whats the difference between :: and . in calling methods? like for >> example: >> >> File::open and File.open >> >> As I understand, you use :: in invoking the constant of a class like >> Math::PI . >> >> Another thing is if i type these in IRB, it returns the same result: >> >> Object::constants >> Object.constants >> >> But if i type this, i get undefined method error >> >> Object.constants.Numeric >> >> whereas this is ok: >> >> Object::constants::Numeric >> >> >> >> So the question now is when do I use the :: and when do I use the . ? > > The :: is never used -- really, I've literally never seen it -- except > when the receiver is a class or module. In such cases, it's sometimes > used, though I've never understood why, as it makes much more sense to > me just to do: > > receiver.message > > regardless of the class of the receiver. Let me clarify that: :: as a method-call operator is never used, except with class/module receivers. :: is also the (one and only) constant path separator. That's why .Numeric doesn't work; Numeric isn't a method. The dual role of :: is what led to your confusion in that example, as it has for many people. David -- David A. Black (dblack / wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" PDF now on sale! http://www.manning.com/black Paper version coming in early May!