ActionView::OutputBuffer - append= and << are not QUITE identical

Not sure if this is the right place for this, but it's certainly to do with core Rails and only of interest to pretty hard-core framework hackers...

Anyways, the issue I ran into was that aliasing a method (<<) to a setter (append=) doesn't quite work the way you'd expect. For instance:

x = ActionView::OutputBuffer.new('something')
result1 = (x << ' else ') # => 'something else'
result2 = (x.append= ('entirely')) # => 'entirely'

In the second example, the return value from the call is the value that was passed in (Ruby's standard behavior for assignments in general). The return value of append= is silently dropped on the floor.

Note that this will never be observed by users of the built-in ERB template parser, since it automatically grabs @output_buffer in the Erubis postamble.

--Matt Jones

Not sure if this is the right place for this, but it’s certainly to do with core Rails and only of interest to pretty hard-core framework hackers…

Anyways, the issue I ran into was that aliasing a method (<<) to a setter (append=) doesn’t quite work the way you’d expect. For instance:

x = ActionView::OutputBuffer.new(‘something’)
result1 = (x << ’ else ') # => ‘something else’
result2 = (x.append= (‘entirely’)) # => ‘entirely’

Unless I’m mistaken, which is often the case, this difference was actually deliberately introduced to allow the backwards compatible support for <%= foo do %> and <% foo do %>.