What does <<-CONSTANT do?

好久不见. 提交于 2019-11-26 08:38:02

问题


return <<-HTML
  <li>
    <a href = \"some-link\">Link-Title</a>
  </li>
HTML

What are <<-HTML on the first line and HTML on the last line for?


回答1:


It's a heredoc.

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




回答2:


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.




回答3:


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

<li>

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

</li>



来源:https://stackoverflow.com/questions/4608902/what-does-constant-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!