Heredocs with leading whitespace removed
Handy if you like to keep things indented.
def initialize
@foo = <<-EOF.gsub /^\s+/, ""
This will not be indented in the resulting string
EOF
end
And a few other clever ways to handle it: http://stackoverflow.com/questions/3772864/how-do-i-remove-leading-whitespace-chars-from-ruby-heredoc
Written by blahed
Related protips
2 Responses
If you're using rails, just use strip_heredoc
: http://apidock.com/rails/v3.2.8/String/strip_heredoc
over 1 year ago
·
Yup, and it handles keeping "real" indentions.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#