1

Possible Duplicate:
What is Ruby's double-colon (::) all about?

What is the "::" telling me in this code example? I'm working thru the ruby koans and don't fully understand this code chuck.

class ::Integer
  def even?
    (self % 2) == 0
  end
end
Community
  • 1
  • 1
David
  • 25
  • 4
  • 4
    not a duplicate of the referenced question. This is more specifically about `::` as a *root-level* namespace identifier, not as a generic scope resolution operator – Gareth Sep 06 '11 at 00:26
  • 1
    Looks like there much more of those, who are able to vote to close a question, that those, who are really understand it. – Nakilon Nov 26 '12 at 09:16

2 Answers2

4

It's going to the root namespace.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • If that's true is there a long form I could use instead? I assume there is nothing ahead of the "::" because that is shorthand for ::Integer? – David Sep 06 '11 at 00:14
  • no, it's the opposite; to say that you're looking for `Integer` in the *top* namespace, *without* anything in front of it. Otherwise, inside of a module `Foo`, a reference to `Integer` would point to `Foo::Integer` if it existed – Gareth Sep 06 '11 at 00:25
-1

It's the namespace resolution operator.

This S/O question has more detail:

What is Ruby's double-colon `::`?

Community
  • 1
  • 1
Russ Clarke
  • 17,511
  • 4
  • 41
  • 45