From: William James Date: 2005-02-08T17:40:09+09:00 Subject: Re: Delayed string interpolation Hal Fulton wrote: > I just wanted to make sure people don't overlook the > obvious: > > > 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" > > > Perhaps there are cases where this is no good though. > > > Hal * Patchworkstr = Struct.new( "Patchworkstring",:start,:middle,:end) * sentence = Patchworkstr.new( "There are " ) * * sentence.end = " solutions." * n = 3**3 * sentence["middle"] = n * * puts sentence.to_a.join ....prints There are 27 solutions.