r/ruby • • Dec 25 '15

Ruby 2.3.0 released

https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/
132 Upvotes

6 comments sorted by

View all comments

3

u/rfdonnelly Dec 26 '15

The best addition didn't make it to the announcement.

From: https://github.com/ruby/ruby/blob/v2_3_0/NEWS

* indented here document:

  * new string literal, here document starts with `<<~`.
    refer doc/syntax/literals.rdoc for more details.
    [Feature #9098]

From: https://github.com/ruby/ruby/blob/v2_3_0/doc/syntax/literals.rdoc

To have indented content as well as an indented closing identifier, you can use a “squiggly” heredoc, which uses a “~” instead of a “-” after <<:

expected_result = <<~SQUIGGLY_HEREDOC
  This would contain specially formatted text.

  That might span many lines
SQUIGGLY_HEREDOC

The indentation of the least-indented line will be removed from each line of the content. Note that empty lines and lines consisting solely of literal tabs and spaces will be ignored for the purposes of determining indentation, but escaped tabs and spaces are considered non-indentation characters.