I make a gem for domestic use. In it, I load some YAML from another directory:
MagicWand::Configuration::Initializer.new(...)
root_yaml = YAML.load_file(
File.expand_path("../../../../data/#{RootFileName}", __FILE__))
---
apple: 100
banana: 200
coconut: 300
I prefer not to depend on location data/root.yamlrelatively initializer.rb. Instead, I would rather get a link to <project_root>and depend on a relative path from there, which seems smarter.
Firstly, is this the best way to do this? Secondly, if so, how do I do this? I have tested various methods File, but I donβt think something like that. I am using Ruby 1.9.
Now I am creating a special constant and rely on it instead:
module MagicWand
ROOT = File.expand_path("../..", __FILE__)
end
but I'm not sure that I like this approach either.