With the 1.9 syntax ruby hashes and YAML are pretty close. I was wondering what ways there are of using a ruby file to retrieve some data.
Given that our config.rb
is something like
{
api: "My key",
name: "name"
}
Option 1
Read and eval the file
config = eval open('./config.rb').read
Option 2
Require the file and then reference a variable
The config.rb file changes to the following (note CONFIG
)
CONFIG = {
api: "My key",
name: "name"
}
And then we can do
require './config'
# ...
config = CONFIG
Are there any other ways of doing this?