Skip to content

Instantly share code, notes, and snippets.

@mxlje
Last active August 10, 2018 17:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxlje/149899ea1ccbc471b192 to your computer and use it in GitHub Desktop.
Save mxlje/149899ea1ccbc471b192 to your computer and use it in GitHub Desktop.
Ruby 2.3.0 heredocs with tilde (~)
# When using heredocs in Ruby 2.3.0, use a tilde (~) instead of a minus (-)
# to remove leading whitespace while keeping indentation in the doc itself.
module I
module AM
module INDENTED
OLD = <<-END
<head>
<title>Hello World</title>
</head>
END
# ~ instead of -
NEW = <<~END
<head>
<title>Hello World</title>
</head>
END
end
end
end
puts I::AM::INDENTED::OLD
# =>
# <head>
# <title>Hello World</title>
# </head>
puts I::AM::INDENTED::NEW
# =>
# <head>
# <title>Hello World</title>
# </head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment