On 18.12.2011, at 0:03, Chad Perrin wrote:

> On Sun, Dec 18, 2011 at 05:20:19AM +0900, ANDREW BIZYAEV (GMAIL) =
wrote:
>> Hello, Ruby experts.
>> Imagine I have single quoted string:=20
>> a =3D 'bla bla #{name} bla bla'
>> name =3D 'Andrew'
>> Is it possible to make a act as double quoted string: puts a =3D> =
'bla
>> bla Andrew bla bla' instead of' bla bla #{name} bla bla'?
>=20
> Why do you need to use single quotes?
I use yaml configuration file. in this file I set string template like =
this:
:event:
  :template: "bla bla #{name} bla bla" #in order to be flexible

Then  I load this yaml into @options variable and define @template:
@template =3D @options[:event][:template] #=3D> "bla bla #{name} bla =
bla" So the effect is the same as using single quotes. And it seems I =
cannot change the way Ruby reads yaml strings.
Later in my program I want to use the @template to generate string with =
real value of name.
I use Steve's approach and it works fine:
a =3D eval "/"#{template}/""  # =3D> "bla bla Andrew bla bla"



>  If you just want to avoid using
> double quotes (perhaps because you want double quotes within the =
string),
> you could use something like this instead:
>=20
>    name =3D 'Andrew'
>    puts %Q{blah blah #{name} blah blah}
>=20
> If you want to be able to reuse the string, you could define a method:
>=20
>    def a(name_input)
>      %Q{blah blah #{name_input} blah blah}
>    end
>=20
>    name =3D 'Andrew'
>=20
>    puts a(name)
>=20
Thank you for advice. You see I have some other case.=