[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Is this old style Ruby?
From: Austin Ziegler <halostatue () gmail ! com>
Date: 2005-02-15 14:28:27
Message-ID: 9e7db91105021506282e711d14 () mail ! gmail ! com
[Download RAW message or body]
On Tue, 15 Feb 2005 23:06:37 +0900, Jeremy Tregunna
<jtregunna@blurgle.ca> wrote:
> On 15-Feb-05, at 8:54 AM, centrepins@gmail.com wrote:
> > In Why's guide, I see the line:
> > File::open( ...etc.
> >
> > Up 'til now I've always written this as:
> >
> > File.open( ...etc.
> >
> > (ie. using a . rather than a ::). Am I right in thinking the :: for
> > accessing class methods is now old-style?
> Foo::bar is for accessing "bar" (be it a method or class or whatever)
> in the module "Foo". Foo.bar wants "bar" in class "Foo".
Mmm. Not really. I can do this, just fine:
module FooMod
def self.bar; puts "FooMod.bar"; end
end
FooMod.bar
FooMod::bar
The difference between :: and . is that :: is used to access constants
or methods and . is used exclusively to access methods. For fun, try
doing:
"foo"::length
-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic