From: "John W. Long" Date: 2003-12-18T14:10:49+09:00 Subject: Re: Configuration Files ----- "Zach Dennis" wrote: ----- > What type of environment would you think something like this would apply to? > > I dont' know what the "previous concept" was and it is hard for me to get a > good grasp in your post. Please help me understand. =) Thanks, If you have ever found yourself storing configuration information in a ruby file setting a bunch of global constants: $TOOLBAR_VISIBLE = true $TOOLBAR_CAPTION = "My Toolbar" . . . and then requiring your 'configuration.rb' into your main program you might consider replacing your current constant based configuration with a file like this: toolbar.visible = true toolbar.caption = "My Toolbar" You can then read it into your program like this: require 'config.rb' $conf = Config.new # define the structure of your configuration object # and the default values for your configuration. $conf.define %{ menu.visible = true toolbar.visible = false toolbar.caption = "Tools" statusbar.visible = true } # we have defined the initial values of our Config object # so we can now use them: puts $conf.toolbar.visible.value #output: false puts $conf.toolbar.caption.value #outputs: "Tools" # most people will want to override the default values # with something of their own, so we will read in the # default values from our configuration file: text = '' File.open('myprogram.conf', 'r') { |file| text = file.read } $conf.read text # we just read in the values from our configuration file # so we can now use them: puts $conf.toolbar.visible.value #outputs: true puts $conf.toolbar.caption.value #outputs: "My Toolbar" # the rest of our program follows . . . I hope this is easier to understand than the last example. Let me know if something is still not clear. ___________________ John Long www.wiseheartdesign.com