From: Gavin Kistner Date: 2005-09-10T22:53:41+09:00 Subject: Re: Using Ruby as a preprocessor for another language On Sep 10, 2005, at 3:26 AM, Malte Milatz wrote: > Gavin Kistner wrote: > [erb] > >> % nps.each do |thug| >> % _erbout << "The thug's name is: #{thug.name}" >> % end >> > > Furthermore, if erb is supposed to send its output to STDOUT, > there's no > problem to simply use "puts" here. There is if you have any literal text in your ERB file. (And if you don't have ANY literal text, then there's not much point in using ERB, is there?) For example: require 'erb' template1 = <<'ENDTEMPLATE' Hello % puts "you crazy" World ENDTEMPLATE ERB.new( template1, nil, '%' ).run #=> you crazy #=> Hello #=> World template2 = <<'ENDTEMPLATE' Hello % _erbout << "you crazy\n" World ENDTEMPLATE ERB.new( template2, nil, '%' ).run #=> Hello #=> you crazy #=> World However, you can use my patch to ERB which makes puts behave as might be expected/desired in the above situation. See http:// blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/152909 for more information.