Ruby 我不知道';我不理解为什么string.size返回它的功能 long_string=

Ruby 我不知道';我不理解为什么string.size返回它的功能 long_string=,ruby,heredoc,Ruby,Heredoc,用于: 工作原理: 如果是哦,请不要引用查尔斯·狄更斯的名言。。。 long_string = <<EOS It was the best of times, It was the worst of times. EOS def test_flexible_quotes_can_handle_multiple_lines long_string = %{ It was the best of times, It was the worst of times. }

用于:

工作原理:


如果是
哦,请不要引用查尔斯·狄更斯的名言。。。
long_string = <<EOS
It was the best of times,
It was the worst of times.
EOS
     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
long_string = <<EOS
It was the best of times,
It was the worst of times.
EOS

String is:
"It was the best of times,\nIt was the worst of times.\n"

It was the best of times, => 25
<newline> => 1
It was the worst of times. => 26
<newline> => 1
Total = 25 + 1 + 26 + 1 = 53
long_string = %{
It was the best of times,
It was the worst of times.
}

String is:
"\nIt was the best of times,\nIt was the worst of times.\n"
#Note leading "\n"
a = "
It was the best of times,
It was the worst of times.
"
a.length # => 54

b = "It was the best of times,
It was the worst of times.
"
b.length # => 53