I'd like to do some config-file work with Ruby. Some elements of the config nominally depend on other elements, but not necessarily.
For example, when using the config, I'd like to do this:
require_relative "config" require_relative "overrides" dosomething_with(Config.libpath) In "config", I want something like:
require 'ostruct' Config = OpenStruct.new Config.basepath = "/usr" Config.libpath = lambda {Config.basepath + "/lib"} # this is not quite what I want In "overrides", the user might override Config.basepath, and I'd like Config.libpath to take the natural value. But the user might also override Config.libpath to some constant.
I'd like to be able to just say Config.libpath and either get the calculated value (if it hasn't been overridden) or the defined value (if it has).
Is this something I'd do with Ruby? It seems like a natural extension of how I've seen OpenStruct work.
OpenStructusesmethod_missingfor its magic, you might as well have a look at that if you don't have an issue with performance