What does <<-CONSTANT do?

前端 未结 3 852
渐次进展
渐次进展 2020-11-28 17:03
return <<-HTML
  
  • Link-Title
  • HTML

    What are <<-HTML on the first lin

    相关标签:
    3条回答
    • 2020-11-28 17:14

      To explicitly answer the question, this snippet returns the string:

      <li>

      <a href = "some-link">Link-Title</a>
      

      </li>

      0 讨论(0)
    • 2020-11-28 17:21

      It's a heredoc.

      http://en.wikipedia.org/wiki/Here_document#Ruby

      0 讨论(0)
    • 2020-11-28 17:22

      That's a here document. Basically, it's a multi-line string literal.

      On lines after the line with the <<-HTML, those are literal strings concatenated by newlines-- until the end marker is reached, which in this case is HTML.

      0 讨论(0)
    提交回复
    热议问题