[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: File::open and File.open

Gavin Kistner

10/23/2006 8:37:00 PM

From: Brad Tilley
> What exactly is the difference between these?

:: and . are interchangeable for method calls (I think fully):
irb(main):001:0> class Foo; attr_accessor :bar; end
=> nil
irb(main):002:0> f = Foo.new
=> #<Foo:0x2c9abd8>
irb(main):003:0> f::bar
=> nil
irb(main):004:0> f::bar = 12
=> 12
irb(main):005:0> f::bar
=> 12


"::" must be used for constant lookup:

irb(main):001:0> class Foo; BAR = 12; end
=> 12
irb(main):002:0> Foo::BAR
=> 12
irb(main):003:0> Foo.BAR
NoMethodError: undefined method `BAR' for Foo:Class
from (irb):3


Most people (I believe) only use "::" for constants, and "." for all
method calls.