-
-
Save stevenringo/ff2a0fc9f5c73c2a00821710bbb9b1e2 to your computer and use it in GitHub Desktop.
Ruby un-indent lines of here document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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