From: Raphael Clancy Date: 2002-02-22T08:39:10+09:00 Subject: Re: confused about '::' vs '.' in method calls Joel VanderWerf wrote in news:3C74446B.40AF1E52@path.berkeley.edu: >>From the pickaxe chapter The Ruby Language: > > ===== > When a receiver is explicitly specified in a method invocation, it may > be separated from the method name using either a period ``.'' or two > colons ``::''. The only difference between these two forms occurs if > the method name starts with an uppercase letter. In this case, Ruby > will assume that a receiver::Thing method call is actually an attempt > to access a constant called Thing in the receiver unless the method > invocation has a parameter list between parentheses. > > Foo.Bar() # method call > Foo.Bar # method call > Foo::Bar() # method call > Foo::Bar # constant access > ===== > > Something that didn't sink in for me right away is that the :: > operator is dynamic in the first argument even when used for constant > access. For example: > > irb(main):001:0> module M > irb(main):002:1> K = 2 > irb(main):003:1> end > 2 > irb(main):004:0> x = M > M > irb(main):005:0> x::K > 2 > > But using the form 'x.K' is an error, because I never defined a method > K. > Thanks! that helps a bunch... looks like I should spend a little more time with irb :) R.