灵活的引号是否为字符串添加了额外的字符?

Ami*_*irh 2 ruby string quotes

当我遇到这两个函数时,我正在通过ruby koans学习红宝石:

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
Run Code Online (Sandbox Code Playgroud)

问题是,当使用灵活的引号时,我无法理解这个额外字符的来源.Ruby koans说两个答案都是正确的.

Mic*_*ohl 5

我会说这是一个换行符%{.

>> test = %{
">> foo
">> }
=> "\nfoo\n"
>> test.size
=> 5
>> test = %{foo
">> }
=> "foo\n"
>> test.size
=> 4
>> test = <<EOS
">> foo
">> EOS
=> "foo\n"
>> test.size
=> 4
Run Code Online (Sandbox Code Playgroud)