Delayed quote expansion



I'm sure the answer to this will seem simple once I see it. Right now
it eludes me.

How can one have a string object like this...

a = '#{some_value}'

and have it get evaluated as a double quoted string (with the value for
some_value being automatically replaced) at a later time?

I would prefer that it is evaluated in context from which it is called.

I would like to do something like this...

def func(param)
test = 42
puts param.quote_substitution
end

func('my number is #{test}') #=> "my number is 42"

_Kevin

--
Posted via http://www.ruby-forum.com/.


.



Relevant Pages

  • Re: Performance on string destruction
    ... I think setting the member to null is just fine. ... to the string object, ... Kevin Yu ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: modify a char in string
    ... There must be a reason for not allowing it. ... > you can't use the indexer on the string object to set chars, ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strings in C are less optimal than in (say) Pascal - correct?
    ... > is the ability to create your own String object that has any of ... I think everyone here who cares already knows that. ... Prev by Date: ...
    (comp.lang.c)
  • Re: Strings and pools
    ... > creates one String object and one reference variable ... The string pool contains String objects not charobjects. ... "abc" the literal is created ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: #,### problem
    ... on the string object. ... this solution will only work for 4 num char so to make it dynamic you will ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)