One of the ways to write a multi-line string in Ruby is the "here document", or "heredoc", with syntax like:
<<~HEREDOC
My multi-line string
literal goes here!
HEREDOC
My understanding is that any identifier (word) can be used in place of where HEREDOC
was used in the above example. (It doesn't have to be the word HEREDOC
.)
Is there a documented best practice -- for code readability, and conformity to standards -- for choosing the name to use in a heredoc declaration?
Observations I've made:
- The official documentation (as of Ruby v3.0) doesn't seem to advocate any particular best practice. It just states:
You may use any identifier with a heredoc, but all-uppercase identifiers are typically used.
- The word
SQL
seems common when defining a SQL statement -- regardless of the purpose of the statement. - Code examples (including in the official documentation, and in the canonical StackOverflow question on multi-line strings in Ruby linked above) often use
HEREDOC
, orEOS
(presumably meaning "end-of-string" -- even though the identifier appears both at the beginning and end of the string literal). - Sometimes, a word describing the value being stored is used as the heredoc identifier -- as is typically done when declaring a standard variable.