Last active
August 29, 2015 14:02
-
-
Save rewinfrey/297fa49abe8d8942b7de to your computer and use it in GitHub Desktop.
Simple example for removing leading whitespace with Ruby's heredoc operator
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
# This is not as sophisticated as ActiveSupport's `strip_heredoc`, but is the simplest solution for | |
# removing leading whitespace. | |
# For more nuanced whitespace removal, take a look at http://apidock.com/rails/String/strip_heredoc | |
puts "With leading whitespace:" | |
puts <<-TEST | |
This is a test. | |
To remove leading spaces. | |
From Ruby's heredoc operator. | |
TEST | |
puts "\nWithout leading whitespace:" | |
puts <<-TEST.gsub(/^ */, "") | |
This is a test. | |
To remove leading spaces. | |
From Ruby's heredoc operator. | |
TEST | |
# >> With leading whitespace: | |
# >> This is a test. | |
# >> To remove leading spaces. | |
# >> From Ruby's heredoc operator. | |
# >> | |
# >> Without leading whitespace: | |
# >> This is a test. | |
# >> To remove leading spaces. | |
# >> From Ruby's heredoc operator. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment