Matt Jones
2011-Oct-09 20:12 UTC
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Michael Koziarski
2011-Oct-09 21:43 UTC
Re: ActionView::OutputBuffer - append= and << are not QUITE identical
On Monday, 10 October 2011 at 9:12 AM, Matt Jones wrote:> 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 %>.> 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 > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com (mailto:rubyonrails-core@googlegroups.com). > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com (mailto:rubyonrails-core+unsubscribe@googlegroups.com). > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.-- Cheers, Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.