# Using variables defined in configuration files

**URL:** <https://www.ruby-forum.com/t/using-variables-defined-in-configuration-files/187257>\
**Category:** Ruby\
**Created:** [April 20, 2010, 5:39pm UTC](https://www.ruby-forum.com/t/using-variables-defined-in-configuration-files/187257 "2010-04-20T17:39:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlucci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@dlucci](https://www.ruby-forum.com/u/dlucci)\
**Post date:** [April 20, 2010, 5:39pm UTC](https://www.ruby-forum.com/t/using-variables-defined-in-configuration-files/187257/1 "2010-04-20T17:39:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dlucci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@dlucci](https://www.ruby-forum.com/u/dlucci)\
**Post date:** [April 20, 2010, 6:09pm UTC](https://www.ruby-forum.com/t/using-variables-defined-in-configuration-files/187257/2 "2010-04-20T18:09:15Z")

</div>

On Tue, Apr 20, 2010 at 5:39 PM, Derril L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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?

This works for me:

jesus@jesus-laptop:~/temp$ cat ~/.myconf.rc  
$test\_variable = 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](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/86660)

Jesus.
