Skip to content

Instantly share code, notes, and snippets.

@ashrithr
Last active May 18, 2017 04:53
Show Gist options
  • Save ashrithr/5905421 to your computer and use it in GitHub Desktop.
Save ashrithr/5905421 to your computer and use it in GitHub Desktop.
Ruby un-indent lines of here document
class String
def undent
gsub(/^.{#{slice(/^ +/).length}}/, '')
end
end
#Usage:
test = <<-EOS.undent
testing unindent
..another line
EOS
puts test.inspect # => "testing unindent\nanother line\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment