> Lett Hal Fulton <hal9000 / hypermetrics.com>
> Aihe: Re: Delayed string interpolation
> 
> Navindra Umanee wrote:
> > Hal Fulton <hal9000 / hypermetrics.com> wrote:
> > 
> >>   def interp(x,y)
> >>     "The sum of #{x} and #{y} is #{x+y}"
> >>   end
> >>
> >>   str = interp(210,27)  #  "The sum of 210 and 27 is 237"
> > 
> > 
> > Unless I'm mistaken, this recomputes the whole string every time
> > interp is called.  I wanted to compute the common parts of the string,
> > cache it somewhere, and then compute the rest in another context.
> > 
> > Hence, a 2-step interpolation.
> 
> Yes, I'm sure there are some efficiency concerns. I've never
> measured the performance in a case like this.
> 
> I wonder if it would be worthwhile to expose the internal
> method which does interpolation? I've thought of this in
> the past, but never seriously enough for an RCR. I think
> that would be "prettier" than an explicit eval.

+1
 
> It would, of course, either have to operate in the current
> binding or have a binding passed in.

Could do something like

  str = "This is a #{var}".nip 

with a corresponding

  str.ip(:here)                # Or
  str.ip(binding)              # Or
  str.ip({var => "SURPRISE!"})

to delay interpolation. #i(nter)p could be implemented such that 
variables not present in the Binding (or maybe a Hash, Array etc.?)
are not substituted to allow for multiple 'levels' of interpolation.
 
> Hal

E