On Jan 1, 2006, at 5:55 PM, Kim wrote:
> Can any one explain the symbole ::? I can not find any refference
> in any
> document. Thanks
>
> Pretty Kim
>
Kim-
Are you refering to the :: between ActiveRecord::Base and other
module and class names like that? Or are you referring the the symbol
''::?'' with the question mark on the end? I haven''t
ever seen ::?
before so I am assuming you meant the former.
Its just a ruby module naming/scoping symbol. If you have this code:
module Ezra
class Zygmuntowicz
# ...
end
module Foo
class Bar
end
class Qux
end
end # module Foo
end #module Ezra
Then you use the :: symbol to call out nested classes and modules.
Like this:
ez = EZRA::Zygmuntowicz.new
OR
foo = Ezra::Foo::Bar.new
OR
foo = Ezra::Foo::Qux.new
Its basically like a path separator for descending into nested
classes and modules. But it can also be used for module or class
methods like this:
module ActiveRecord
def self.foo
return "bar"
end
end
a = ActiveRecord::foo
p a
#=> "bar"
so you can call the module method foo to have it run without
instantiating ActiveRecord since it is a module not a class. So its
pretty simple what its used for but since it is kind of a split
personality with it being used as a replacement for . as the method
call syntax and its use as a path to descend into modules and classes.
Cheers-
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732