Created
June 17, 2015 18:33
-
-
Save squarism/1917084c554375d2fbcd to your computer and use it in GitHub Desktop.
Stripping leading whitespace in ruby heredocs
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
# <<foo doesn't trim leading whitespace. No problem. :cake: | |
<<EOS | |
hi | |
EOS | |
=> " hi\n" | |
# I thought the difference between << and <<- was the leading whitespace trimming. | |
<<-EOS | |
hi | |
EOS | |
=> " hi\n" | |
# Am I missing something? Almost all of homebrew monkey patches string to "unindent" heredocs. | |
# Some people use gsub. Some people monkey patch string. That's fine I guess. | |
# I think I would use the activesupport gem in a bigger project. | |
# In a smaller project, just use unindent from homebrew. | |
require 'active_support/core_ext' | |
test = <<EOS | |
hi | |
EOS | |
=> " hi\n" | |
test.strip_heredoc | |
=> "hi\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment