0

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

pardon for my laziness. I tried to guess. I am not sure what the double '::Logger' does in this case?

https://github.com/wycats/rack-offline/blob/master/lib/rack/offline.rb#L25

it seems like it is initializing the object and assign it on a variable that is not in its scope? line 25 is wrapped by {begin/end} block and gets assigned to @logger

Community
  • 1
  • 1
dvliman
  • 606
  • 2
  • 7
  • 13

1 Answers1

3

Just like a / in a path defines nested directories, :: accesses nested classes.

And also similarly to a leading /, a leading :: means to start at the the very top of the tree. It starts searching for constants at the global scope.

# Bar declared in global scope
class Bar
end

# Foo declared in global scope    
class Foo

  # A different class named Bar declared in the scope of Foo, not global
  class Bar
  end

  Bar   #=> refers to Foo::Bar, that is class Bar declared within Foo
  ::Bar #=> refers to outer global scope class named Bar

end
Alex Wayne
  • 178,991
  • 47
  • 309
  • 337