I am creating a gem where I'd like to define some constants to be available.
In my actual gemspec, I added the following:
config = File.expand_path('../config', __FILE__)
$LOAD_PATH.unshift(config) unless $LOAD_PATH.include?(config)
require 'constants.rb'
In constants.rb I have a simple var defined: $FOO = "Hello, World!"
Then in my lib/gem_name/core.rb, I'm attempting to puts $FOO but it doesn't seem to be available. No error, just comes up blank. Am I not understanding how gem dependencies and the require tree works here?
** UPDATE **
I have also tried just adding a config directory directly underneath lib which is in the LOAD_PATH already. then in my library, I am attempting to require config/constants, but that's saying it cannot load such a file.
I have also tried just moving constants.rb to the lib directory directly and requiring that, and it's warning me that it cannot load such file. Something is terribly wonky.
According to Katz,
That means that
require 'constants.rb'and$LOAD_PATH.unshift(...)etc are run when you build the gem. At runtime, it doesn't change the$LOAD_PATHor cause a global require. Usegem.require_pathsinstead to modify$LOAD_PATHat runtime.For example, in your gemspec, use
Then in places where
$FOOis required, useSide Notes
.rbextension when usingrequire.gem.files.