From: "ara.t.howard" Date: 2007-11-09T11:30:02+09:00 Subject: Re: local variables, eval, and parsing On Nov 8, 2007, at 3:04 PM, furtive.clown@gmail.com wrote: > Remember the motivation was to have a separate config file for these > variables. Unless ruby has something akin to the C-preprocessor > #include then we are stuck with reading a file, which means we are > stuck with a string, which means we are stuck with eval, which means > we are stuck with ugly hacks in order to obtain local variables. cfp:~ > cat a.rb require "attributes" ### gem install attributes class Config attribute "width" attribute "height" attribute "color" def self.load path config = new config.instance_eval IO.read(path) config end def configure &block instance_eval &block end end config = Config.load "b.rb" p config config.configure{ width 42.0 } p config cfp:~ > cat b.rb configure { width 42 height 42.0 color "pinky-beige" } cfp:~ > ruby a.rb # # it's true that they are not local vars but i think the effect is useful enough. a @ http://codeforpeople.com/ -- it is not enough to be compassionate. you must act. h.h. the 14th dalai lama