From: dblack@... Date: 2006-04-26T00:55:32+09:00 Subject: Re: difference between :: and . in calling methods 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. I would love to see :: removed, except for its other purpose of constant lookup. (It also occasionally, and understandably, causes confusion because of that dual role.) 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!