From: "Ara.T.Howard" Date: 2005-09-12T03:44:27+09:00 Subject: Re: r4 - the simplest ruby pre-processor On Mon, 12 Sep 2005, Christian Neukirchen wrote: > Bob Hutchison writes: > >>>>> That one change is from: >>>>> >>>>> >>>>>> "puts #{line.chomp.dump}\n" >>>>>> >>>>> >>>>> to: >>>>> "puts \"#{line.chomp}\"\n" >>>>> (just added the quotes). >>>>> >>>> >>>> and lost the dump >>>> >>> >>> And broke it. >>> | blah = 42 >>> Hello. I'm an evil template. ", `rm -rf /`, "I advise against >>> running me as root. >>> >>> Devin >>> >> >> Broke it? Nah, it was already 'broken'. And anyway, that's what I >> wanted to do, and really would've 'broken' it to achieve that :-) > > You broke it because " can't appear as-is in the file anymore. > (Which is likely what I want when I code C or something.) fixed: harp:~ > cat in | x = 42 using the -i switch i can interpolate x as #{ x } quote " works quote ' works harp:~ > r7 in using the -i switch i can interpolate x as #{ x } quote " works quote ' works harp:~ > r7 --interpolate in using the -i switch i can interpolate x as 42 quote " works quote ' works harp:~ > cat r7 #! /usr/bin/env ruby def macro(m, &b); Kernel::send('define_method', m){|*a| puts b.call(a)}; end d = $DEBUG || ENV['DEBUG'] || ARGV.delete('-d') || ARGV.delete('--debug') i = $INTERPOLATE || ENV['INTERPOLATE'] || ARGV.delete('-i') || ARGV.delete('--interpolate') h = '_' * 42 m = d ? 'puts' : 'eval' s = ARGF.readlines.map{|l| l =~ %r/^\s*\|(.*)/ ? $1 : (i ? %Q(puts <<#{ h }\n#{ l.chomp }\n#{ h }) : %Q(puts #{ l.chomp.dump }))} send m, s.join("\n") -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================