Skip to content

Instantly share code, notes, and snippets.

@stevenringo
Forked from ashrithr/undent.rb
Created May 18, 2017 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenringo/ff2a0fc9f5c73c2a00821710bbb9b1e2 to your computer and use it in GitHub Desktop.
Save stevenringo/ff2a0fc9f5c73c2a00821710bbb9b1e2 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