On Wed, 2003-02-19 at 00:20, Bjöòn Lindströí wrote: > I like using source files as configuration files for my hacks. > > In shell I can easily do that by putting: > > source ~/.configfile > > or something like that at the top of the script. > > Then I can put whatever settings I like in ~/.configfile > > There seems to be no straightforward way to do that in Ruby, > neither with eval or with require/include. I do this too. In fact, I tend to use the same file for both Ruby and shell. Suppose the config file has format KEYWORD=VALUE ANOTHERKEYWORD=Still another value etc. That file can be sourced directly into a shell script, and read into a Ruby program with the following code ... def read_config(config_file) result = {} open(config_file) do |file| while line = file.gets key, value = line.chomp.split("=") result[key] = value end end result end read_config returns a hash table containing the keys and the values. A little extra code can handle comments and blank lines and you have a quick and dirty config reader. True, it isn't quite what you asked for, but I've found it to be quite useful. And I really like that one config file works for both Ruby and shell. Of course, if your config data is more than just simple keyword/values, I would suggest taking a look at YAML (or <shudder> XML). -- -- Jim Weirich jweirich / one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)