What does '::' actually mean?

HI everyone,

I’m just getting my head around Ruby/RoR syntax & wondered exactly
what the colon/colon means in the example below ( and similar
contexts ) ? ( I see that the < is inheritance )

I’ve read it is something to do with Class Methods ?

I also assume it is Ruby ? not RoR

e.g.
class ApplicationController < ActionController::Base

TIA - Dave P.

Its a ruby thing. Maybe this will help, the abridged source to the
example you gave

module ActionController
class Base
#…bunch of code…
end
end

And then that is referenced as

ActionController::Base

Usually I imagine it as a namespace thing. The module is
ActionController. The specific class is Base.

There is actually more to it but thats a start.

On Sun, 23 Dec 2007 01:22:17 -0800, Davo wrote:

I’ve read it is something to do with Class Methods ?

I’m a newbie to ruby, and this is really a ruby question, rather than a
rails question, but, yes, it signifies class methods.

An instance method will give varying results – unique to each instance
(object). The simplest example of an instance method (coming from Java)
would be the getter/setter methods.

foo.set_var = 5
foo.print_var #will print “5”

bar.set_var = 10
bar.print_var #will print “10”

Here, the same method will give different results. For object foo, the
result is 5, for object bar the result is 10.

Conversely, consider:

myMath.sin(x)

Do you want the above to give different results for different instances?
I would hope not!

-Thufir

Thanks to everyone for their help…
Merry Xmas to all.
Dave

I have a screencast for this “Modules in Ruby”. Check it out.

On Dec 23, 2007 1:22 AM, Davo [email protected] wrote:

HI everyone,

I’m just getting my head around Ruby/RoR syntax & wondered exactly
what the colon/colon means in the example below ( and similar
contexts ) ? ( I see that the < is inheritance )


http://www.rubyplus.org/
Free Ruby Screencasts

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs