Donnerstag, 26. April 2007

Really simple templates with ruby

Example:
template = 'Hello #{name}!'
name = 'Paul'
puts eval(%{"#{template}"}) # => Hello Paul!
name = 'Holger'
puts eval(%{"#{template}"}) # => Hello Holger!
Note that the template definition use a single qutoed string, so no variables are evaluated within the template string.
Also note that the template can't use unescaped double quotes, because the template evaluation uses them to delimit the template string.

Labels: ,

0 Kommentare:

Kommentar veröffentlichen

Links zu diesem Post:

Link erstellen

<< Startseite