【发布时间】:2011-09-14 07:58:06
【问题描述】:
long_string = <<EOS
It was the best of times,
It was the worst of times.
EOS
返回 53。为什么?空格算不算?即便如此。我们如何得到 53?
这个怎么样?
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 视为一个字符,并且在第一行之前被认为是一个字符,在末尾一个,然后在第二行末尾,而在 @ 987654324@ 情况下只有一个在第一行之前和一个在第一行之后?也就是说,为什么前者是54,后者是53?
【问题讨论】:
-
哦,请不要引用查尔斯狄更斯的名言......