Using variables defined in configuration files

D

Derril Lucci

Greetings all,
I recently posted about how to import a configuration file. I got
this as a reply:

load File.join(ENV['HOME'], '.myconfrc')

file ~/.myconfrc:

$interval = 15

But when I go to run it, I get this:

test.rb:3: unterminated string meets end of file
test.rb:3: syntax error, unexpected tSTRING_END, expecting
tSTRING_CONTENT or tREGEXP_END or tSTRING_DBEG or tSTRING_DVAR

Anything help would be appreciated. Also, the configuration file has
some variables in it. How would I access those variables?

Cheers,
dlucci
 
J

Jesús Gabriel y Galán

Greetings all,
=A0I recently posted about how to import a configuration file. =A0I got
this as a reply:

load File.join(ENV['HOME'], '.myconfrc')

file ~/.myconfrc:

$interval =3D 15

But when I go to run it, I get this:

test.rb:3: unterminated string meets end of file
test.rb:3: syntax error, unexpected tSTRING_END, expecting
tSTRING_CONTENT or tREGEXP_END or tSTRING_DBEG or tSTRING_DVAR

Anything help would be appreciated. =A0Also, the configuration file has
some variables in it. =A0How would I access those variables?

This works for me:


jesus@jesus-laptop:~/temp$ cat ~/.myconf.rc
$test_variable =3D 15
jesus@jesus-laptop:~/temp$ cat test_config.rb && ruby test_config.rb
load File.join(ENV['HOME'], ".myconf.rc")

puts $test_variable

15


So check that you don't have unmatched quotes in either of the files.
You can do as the example and use global variables, or there are some
gems out there that do similar stuff for configuration files. Maybe
you can check what they do.

I found this thread through google, it can give you some ideas:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/86660

Jesus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top