From: William James Date: 2005-09-10T14:36:30+09:00 Subject: Re: Using Ruby as a preprocessor for another language debbie@theanimaro.com wrote: > I've been using Ruby as a macro pre-processor so that I can write more > maintainable scripts without violating the DRY (Don't Repeat Yourself) > principle. Presently, I have the following functionality: > > 1. #{...} strings are evaluated by Ruby > 2. lines starting with @ are evaluated by Ruby > > Thanks to Ruby's power and simplicity, the ENTIRE pre-processor is > just these few lines: > > while line = gets > line.chomp! > if line =~ /^\s*\@(.*)$/ > # Line starts with a @; it is Ruby code > puts $1 > else > # Line should be printed, with #{} substitution > available > puts "puts \"#{line.gsub('"', '\"')}\"" > end > end /^\s*\@(.*)$/ could be changed to /^\s*@(.*)$/