我在将 Rails 代码从 Ruby 1.8.7 移动到 1.9.2 时遇到问题。我不明白 Ruby 的行为。
我有一个只有一个元素(字符串)的数组。
my_var = [“Bla blubb and foo bar”]
然后我打电话:
some text #{my_var}
在 Ruby 1.8 中我得到 some text Bla blubb and foo bar
.
在 Ruby 1.9 中我得到 some text [\"Bla blubb and foo bar \"]
为什么会有差异?我怎样才能避免这种行为?
最佳答案
您正在对字符串数组调用 to_s。在1.8中相当于调用join,在1.9中相当于调用inspect。 要在 1.8 和 1.9 中获得您想要的行为,请调用 join 而不是 to_s。
关于ruby-on-rails - 将代码从 Ruby 1.8 移至 1.9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6178347/