[LRUG] Concat and Strings

Damian Janowski damian.janowski at gmail.com
Tue May 13 08:00:59 PDT 2008


On Tue, May 13, 2008 at 11:45 AM, Andrew Stewart
<boss at airbladesoftware.com> wrote:
> > BTW, you may want to avoid calling capture as much as possible:
> >
> > def wrap(with, &block)
> >  concat("#{with} {", block.binding)
> >  yield
> >  concat("}", block.binding)
> > end
> >
>
>  Yes, I agree it's unnecessary here.  I separated out the capture so I could
> print its result for debugging -- I'll ditch it when I figure out what's
> going on.  By the way, did you mean there's something actually wrong with
> capture?

Well, the only way capture can achieve what it does is by yielding the
block and extracting the newly appended string from _erbout:

        def capture_erb_with_buffer(buffer, *args, &block)
          pos = buffer.length
          block.call(*args)

          # extract the block
          data = buffer[pos..-1]

          # replace it in the original with empty string
          buffer[pos..-1] = ''

          data
        end

Not very elegant... :) Especially when most times you capture and then
(re-)concat...



More information about the Chat mailing list