Can I somehow use this
settings = {
'user1' => { 'path' => '/','days' => '5' },
'user2' => { 'path' => '/tmp/','days' => '3' }
}
in a external file as settings?
How can I include this into my script?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The most common way to store configuration data in Ruby is to use YAML:
settings.ymlThen load it in your code like this:
You can create the YAML file using
to_yaml:That said, you can include straight Ruby code also, using
load:However, you can’t access local variables outside the file, so you would have to change your code to use an instance variable or a global variable:
settings.rbThen load it thus: