Triple single quote vs triple double quote in Ruby

后端 未结 4 1124
天涯浪人
天涯浪人 2021-01-06 08:13

Why might you use \'\'\' instead of \"\"\", as in Learn Ruby the Hard Way, Chapter 10 Study Drills?

4条回答
  •  青春惊慌失措
    2021-01-06 08:57

    I assume the author confused Ruby and Python, because a triple-quote will not work in Ruby the way author thought it would. It'll just work like three separate strings ('' '' '').

    For multi-line strings one could use:

    %q{
     your text
     goes here
    }
     => "\n     your text\n     goes here\n    "
    

    or %Q{} if you need string interpolation inside.

提交回复
热议问题