From: "drbrain (Eric Hodel)" Date: 2013-11-14T13:01:55+09:00 Subject: [ruby-core:58328] [ruby-trunk - Feature #9098] Indent heredoc against the left margin by default when "indented closing identifier" is turned on. Issue #9098 has been updated by drbrain (Eric Hodel). Target version changed from Next Major to next minor Creating a patch will help, but it can't be committed without the approval of matz. ---------------------------------------- Feature #9098: Indent heredoc against the left margin by default when "indented closing identifier" is turned on. https://bugs.ruby-lang.org/issues/9098#change-42923 Author: sikachu (Prem Sichanugrist) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: syntax Target version: next minor tl;dr: I would like to port +String#strip_heredoc+ (http://api.rubyonrails.org/classes/String.html#method-i-strip_heredoc) from Rails and enable it on `<<-` heredoc. Hi, I've been using here document (heredoc) for a while, and I've found out that it's very annoying that the content is always treated as flushed left. Per syntax doc: Note that the while the closing identifier may be indented, the content is always treated as if it is flush left. If you indent the content those spaces will appear in the output. So, this is the current result if you use heredoc in Ruby: class FancyHello def self.hello puts <<-README.inspect Hello World! README end end FancyHello.hello # => " Hello\n World!\n" In Rails, the core team has implemented +String#strip_heredoc+, which handles this scenario by remove leading white spaces from the string. However, not many user know that Rails has that method, and instead doing this to get around it: class FancyHello def self.hello puts <<-README.inspect Hello World! README end end FancyHello.hello # => "Hello\n World!\n" I really think that we could do better on this by removing the leading white spaces, matching +String#strip_heredoc+ method. So, after the change, I want to be able to do this, and get this result: class FancyHello def self.hello puts <<-README.inspect Hello World! README end end FancyHello.hello # => "Hello\n World!\n" Note: the behavior on `<