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