From: Jeremy Kemper Date: 2010-03-27T05:30:00+09:00 Subject: [ruby-core:29051] Re: [Feature #889] erb.rb should use Array and << for eoutvar and not String and concat On Fri, Mar 26, 2010 at 11:45 AM, Kurt Stephens wrote: > Issue #889 has been updated by Kurt �Stephens. > > > This is not a good idea, because the expression value Strings accumulated in the Array must be protected from mutation. > ERB expressions can have side-effects. > >
> SOME_STRING = 'foobar'
> def foo
> �SOME_STRING
> end
> def bar
> �SOME_STRING.sub!(/bar/, '')
> �SOME_STRING
> end
> # ERB GENERATED CODE: from "<%= foo %><%= bar %>"
> eoutvar = [ ]
> eoutvar << foo
> eoutvar << bar
> eoutvar.join('')
> 
I disagree. That's based on a loose assumption that <%= ... %> behaves like #{...}. But all it says is "output" not necessarily "interpolate" -- that's a side effect of the current implementation. Much like using <% .... # comment %> was an assumption that later broke. jeremy