From: Gavin Kistner Date: 2005-08-19T13:25:51+09:00 Subject: Re: #puts inside ERB On Aug 18, 2005, at 8:47 AM, Gavin Kistner wrote: > How would I patch ERB so that puts and print were aliased to > concatenate onto the current eoutvar? This aliasing should be setup > at the beginning of #result, and removed at the end of #result. Here's my horrific hack that does it. It's particularly hacky because it requires that the 'eoutvar' be set to have a @ at the beginning of the name (an instance variable). The real solution I suppose requires a change to the ERB::Compiler#compile method, to replace calls to puts and print with the local variable concatenation inline. But that was beyond my foo. #in the ERB class def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout') @safe_level = safe_level compiler = ERB::Compiler.new(trim_mode) set_eoutvar(compiler, eoutvar) @src = <<-ENDIOBORK module Kernel alias_method :_oldputs, :puts alias_method :_oldprint, :print def puts(s) #{eoutvar}<