I recently used the <<- operator to output a multi-line string, like this:
<<-form
Name to say hi!
The reason why you cannot find any documentation on the <<-
operator is because it isn't an operator. It's literal syntax, like '
or "
.
Specifically, it's the here document syntax which is one of the many syntactic forms of string literals in Ruby. Ruby here documents are similar to POSIX sh
here documents, but handling of whitespace removal is different: in POSIX sh
here documents delimited by <<-
, only leading tabs are removed, but they are removed from the contents of the string, whereas in Ruby all leading whitespace is removed, but only from the delimiter.