Re: How to do this
- From: Stefano Crocco <stefano.crocco@xxxxxxxx>
- Date: Tue, 12 Oct 2010 08:25:25 -0500
On Tuesday 12 October 2010, Damjan Rems wrote:
|I don't know how to explain so I will just code:
|
|template = 'some text #{variable}' # single quotes for reason
|variable = 'filled'
|res = some_method(template)
|
|Here, res should have value 'some text filled'.
|
|Is there an easy way doing this in ruby. Hard way is of course parsing
|and inserting text with my own method.
|
|by
|TheR
You could do this:
#note the double quotes inside the single ones
template = '"some text #{variable}"'
variable = 'filled'
res = eval template
A better way could be to use ERB (included in the standard library):
require 'erb'
template = ERB.new "some text <%= variable %>"
variable = 'filled'
res = template.result
I hope this helps
Stefano
.
- References:
- How to do this
- From: Damjan Rems
- How to do this
- Prev by Date: Re: Help with regexp's
- Next by Date: Re: OT: file attribute serialization in Windows
- Previous by thread: Re: How to do this
- Next by thread: Help with regexp's
- Index(es):