From: Christian Neukirchen Date: 2005-09-11T20:38:08+09:00 Subject: Re: r4 - the simplest ruby pre-processor "Ara.T.Howard" writes: > all this talk about pre-processors and erb got me thinking : what would it > take to code up a ruby pre-procssors that could be used for any laguange. my > first crack is 38 lines of ruby that pre-process any files on the command line > (or stdin) using ruby as the macro language and a convenience function 'macro' > which can be used to define ruby methods which return test that is used as > output. functions declared this way need not do any explicit io. Alternative implementation ("r5"): def macro(name, &block) Kernel.send(:define_method, name) { |*args| puts block.call(args) } end send(($DEBUG ? "puts" : "eval"), ARGF.readlines.map { |line| if line[0] == ?| line[1..-1] else "puts #{line.chomp.dump}\n" end }.join) Happy hacking, -- Christian Neukirchen http://chneukirchen.org