I have a problem moving Rails code from Ruby 1.8.7 to 1.9.2. I do not understand the behaviour of Ruby.
I have an Array with one element (a string).
my_var = [“Bla blubb and foo bar”]
Then I call:
some text #{my_var}
In Ruby 1.8 I get some text Bla blubb and foo bar.
In Ruby 1.9 I get some text [\"Bla blubb and foo bar \"]
Why is there the difference? How can I avoid this behaviour?
You’re calling to_s on an array of strings. In 1.8 that is equivalent to calling join, in 1.9 it is equivalent to calling inspect.
To get the behavior you want in both 1.8 and 1.9, call join instead of to_s.