long_string = <<EOS
It was the best of times,
It was the worst of times.
EOS
返回53.为什么?空白的数量?即使如此。我们如何得到53?我不明白为什么string.size返回它所做的
这个怎么样?
def test_flexible_quotes_can_handle_multiple_lines
long_string = %{
It was the best of times,
It was the worst of times.
}
assert_equal 54, long_string.size
end
def test_here_documents_can_also_handle_multiple_lines
long_string = <<EOS
It was the best of times,
It was the worst of times.
EOS
assert_equal 53, long_string.size
end
是这种情况,因为%{情况下,可计算每个/n
为一个字符,被认为是一个第一行之前,一个在端孤单,然后在第2行的末尾,而在EOS
这种情况在第一行之前只有一个,第一行之后有一个?换句话说,为什么前者54和后者53?
哦,请不狄更斯行情... – alternative 2011-06-14 00:14:04