From: Gavin Kistner Date: 2005-09-20T23:27:51+09:00 Subject: Re: RCR to modify #puts and #print inside ERB --Apple-Mail-3-742888928 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Sep 20, 2005, at 8:12 AM, Paul Brannan wrote: > On Sat, Sep 10, 2005 at 11:12:21PM +0900, Gavin Kistner wrote: > >> Proposed RCR: >> >> Modify ERB so that calls to #puts, #print, and #p inside the template >> append the resulting string onto the local ERB output variable, >> instead of sending the output to $stdout. #warn would still send to >> STDERR (for debug messages seen but kept out of the result string) >> and $stdout#<< could also be used. >> > > Why not just change $stdout, e.g.: > > <% > require 'stringio' > $orig_stdout = $stdout > $stdout = StringIO.new(_erbout, 'a') > $stdout.sync = true > %>1 > <% puts "2" %>3 > <% $stdout = $orig_stdout %> > > should print: > > 1 > 2 > 3 > > Then puts keeps the same behavior as it has now, and you get the > result > you want using the existing behavior. If you're suggesting putting this at the top of every ERB template, then that's the reason not to do it. The purpose of this idea (which I've mostly abandoned, seeing how many are against it) was to make puts and print "just work", so that you don't have to think of ERB as different from any other ruby program. The above certainly provides a way for puts and print to work, but it requires too much effort. --Apple-Mail-3-742888928--