Andreas Lundgren wrote in post #1000535:
> First params does not contain a simple string;
> please note the escaped string characters in the code
> that generates params. Kind of strings within strings

Yes, I noted that--see comment 6).  What I failed to recognize was that
the line:

  params = #{params}

was part of a multiline string.



> "1) Strings are mutable in ruby, so get rid of all those +'s." - I'm
> not sure that I understand this but it sounds interesting, what does
> it mean?
>

Every quoting mechanism creates a string and every + creates a new
combined string.  So it's more efficient to use string interpolation:

i = 2
params = 'x1.to_s'
params = "#{params}, x#{i}.to_s"
p params

--output:--
"x1.to_s, x2.to_s"


In ruby not only can you push elements onto an array with the << method,
you can also push a string onto another string with the << method--which
alters the first string:


i = 2
params = 'x1.to_s'
params = "#{params}, x#{i}.to_s"

puts params
puts params.object_id

params << ', x3.to_s'

puts params
puts params.object_id

--output:--
x1.to_s, x2.to_s
77684510
x1.to_s, x2.to_s, x3.to_s
77684510

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