#!/usr/bin/ruby class ElConfig attr_accessor :opt def initialize() @opt = Hash.new(nil) end def load() lines = IO.readlines("config.txt") # allow a second config file (e.g. for developers), but not mandatory # like the first one is begin lines.push(IO.readlines("config2.txt")) rescue SystemCallError end lines.flatten.each do |line| # Remove comments (TODO: escape comments with (an even number of) '\') line.sub!(/#.*/, "") line.strip! # Skip blank lines next if line == '' if line =~ / ^ (.*?) \s* = \s* (.*?) $ /x @opt[$1] = eval $2 if @opt[$1] == :prompt print "Need a value for option '"+$1+"': " @opt[$1] = gets.chomp end else raise "config.txt:" + $..to_s + ": Each option must be of the form ``option = value''" end end @opt.each do |key, value| if value == :prompt_end print "Need a value for option '"+key+"': " @opt[key] = gets.chomp end end end end