The singleton design pattern I’m relatively new the the concept of the singleton, even though I’ve been programming for a number of years. I’ve run into several instances in which I new that this was exactly what I needed, but did not have a name for it. Here, I’m going to try to explain it to myself a year ago. There are a few questions I’ll try to address.
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.