问题
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