From: William James Date: 2005-11-29T06:47:29+09:00 Subject: Re: string substitution question Ross Bamford wrote: > On Mon, 28 Nov 2005 12:00:37 -0000, wrote: > > > What is ERB? > > > > I had assumed that it would be possible to convert a single quote > > string to a double quote string and that would take care of it. Is > > that not possible. Maybe I'm looking at this the wrong way. > > Substitution is done with the syntax you mention in my current version > > of Rails. Is ERB what they use? > > > > It is probably possible, maybe using the special quoting operators and so > forth, but I imagine it is messy and problematic (?). > There appears to be some automagic escaping going on when # is read into > double quoted strings, or something like that. > Rails does use ERB, and I think I'd still suggest it. It's 'Embedded > Ruby'. With 1.8 it comes as standard (at least with 1.8.3). You can use it > like: > > require 'erb' > > sturf = ['just', 'some', 'stuff'] > src = "<% sturf.length.times do |i| %><%= sturf[i] %> <% end %>" src = "<% stuff.each do |s| %><%= s %> <% end %>" > > text = ERB.new(src).result # => "just some stuff "