Created
March 21, 2016 12:53
-
-
Save tex2e/1bcbe96c2a1fd5570d20 to your computer and use it in GitHub Desktop.
strip indentation for Ruby heredoc
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
# strip indentation | |
class String | |
def dedent | |
margin = self.scan(/^ +/).map(&:size).min | |
self.gsub(/^ {#{margin}}/, '') | |
end | |
end | |
def usage | |
puts <<-EOS.dedent | |
Overview: | |
foo bar baz | |
Usage: | |
foo <spam> <ham> <eggs...> | |
EOS | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment