Last active
August 10, 2018 17:19
-
-
Save mxlje/149899ea1ccbc471b192 to your computer and use it in GitHub Desktop.
Ruby 2.3.0 heredocs with tilde (~)
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
# 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