Created
December 31, 2015 19:01
-
-
Save carlzulauf/18f272828cec9d59715c to your computer and use it in GitHub Desktop.
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 MyStrings | |
def dash_heredoc | |
<<-HEREDOC | |
This is a multiline string in Ruby using the older indented syntax. | |
These lines will have a bunch of leading whitespace. | |
HEREDOC | |
end | |
def squiggly_heredoc | |
<<~HEREDOC | |
This is a multiline string in Ruby using the new squiggly HEREDOC syntax. | |
These lines should have no leading whitespace... | |
...unless they are indented deeper than the shallowest line. | |
HEREDOC | |
end | |
end | |
strings = MyStrings.new | |
puts "Old indented heredoc (<<-):" | |
puts | |
puts strings.dash_heredoc | |
puts | |
puts "New squiggly heredoc (<<~):" | |
puts | |
puts strings.squiggly_heredoc | |
puts | |
# OUTPUT: | |
# Old indented heredoc (<<-): | |
# | |
# This is a multiline string in Ruby using the older indented syntax. | |
# These lines will have a bunch of leading whitespace. | |
# | |
# New squiggly heredoc (<<~): | |
# | |
# This is a multiline string in Ruby using the new squiggly HEREDOC syntax. | |
# These lines should have no leading whitespace... | |
# ...unless they are indented deeper than the shallowest line. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment