The <<- operator on Ruby, where is it documented?

后端 未结 5 487
执笔经年
执笔经年 2020-12-03 05:31

I recently used the <<- operator to output a multi-line string, like this:

<<-form
  

Name to say hi!

5条回答
  •  伪装坚强ぢ
    2020-12-03 06:26

    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.

提交回复
热议问题