Last active
May 18, 2017 04:53
-
-
Save ashrithr/5905421 to your computer and use it in GitHub Desktop.
Ruby un-indent lines of here document
This file contains 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