0

When rails application is created, there is a line in config.ru file:

require ::File.expand_path('../config/environment',  __FILE__)

Could you explain, why we need ::File and not just File? Will require File.expand_path work?

Alex Smolov
  • 1,831
  • 4
  • 24
  • 43
  • I do understand what the `::` operator is. The question is about a particular usage. Do we need it in front of `File` in `config.ru`? How different `::File` is in comparison with `File`? – Alex Smolov Jan 05 '14 at 18:59

1 Answers1

2

:: at the beginning represents the main name space. Suppose the current environment is within module A. If you have just File, then it will first look for A::File, and only when such constant does not exist does it look for File in the main name space. On the other hand, ::File refers to File in the main name space regardless of whether there is such thing as A::File.

sawa
  • 165,429
  • 45
  • 277
  • 381