Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Created December 31, 2015 19:01
Show Gist options
  • Save carlzulauf/18f272828cec9d59715c to your computer and use it in GitHub Desktop.
Save carlzulauf/18f272828cec9d59715c to your computer and use it in GitHub Desktop.
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