Forum: Ruby on Rails ::?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
::?
Kim (Guest)
on 2006-01-02 03:55
Can any one explain the symbole ::? I can not find any refference in any
document. Thanks

Pretty Kim
Forrest T. (Guest)
on 2006-01-02 05:49
(Received via mailing list)
Kim <kimynow@...> writes:

> Can any one explain the symbole ::? I can not find any refference in any
> document. Thanks

I haven't seen that one before--where did you find it?

A good reference for Ruby's "funny symbols" is:
   http://www.rubygarden.org/ruby?FunnySymbolsInCode

--Forrest
Ezra Z. (Guest)
on 2006-01-02 07:43
(Received via mailing list)
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 Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732
This topic is locked and can not be replied to.