Bits and Blocks

The Mysteries of the Ruby Heredoc

4 minute read Published:

A few tips on the ruby heredoc.
As of writing this, I’m running Ruby version 2.3.0. Not all of this, particularly the stripped heredoc, is available in plain ruby before 2.3.0. Heredoc Basics So, you need a string that’s longer than a line, and you’re sick of quotes and backslashes? And you might like to retain formatting? You want string interpolation too? Enter, heredoc. Here’s your basic, run of the mill, heredoc. You’ll notice we use the <<- operator, and our safe-word, which we will use to end the heredoc.