Constants are global, but they live in the namespace in which they are defined.
If you define CONFIG in the main context, it will be global at the root-level. If you define it in a class or module, you must refer to it by its full name outside of that context.
For example:
class Foo
CONFIG = File.read(...)
end
CONFIG # => Error, not defined
Foo::CONFIG # => Defined
It's generally bad form to reference constants by name, they run against the grain of proper object-oriented design. As such, if you define constants, they should be used internally only, and exposed via methods that sub-classes can redefine or patch as required.
A better example:
class Foo
CONFIG = File.read(...)
def self.config
CONFIG
end
end
Foo.config # => Your configuration
This simple abstraction is important because a sub-class can re-define your configuration:
class Bar < Foo
def self.config
# ... Different implementation
end
end
Bar.config # => Different result
Even better is to avoid constants altogether and simply lazy-load things as required:
class Foo
def self.config
@config ||= File.read(...)
end
end
Foo.config # => Your configuration
Constants are best reserved for things that do not change, like SEPARATOR = ':', where it's not possible or practical to reconfigure them without breaking a lot of code.
Where you have something that's read in from an external source, where it might vary based on configuration or preference, it's usually more convenient to have a method that intermediates this.