About the Ruby squiggly heredoc syntax

To my list of Ruby achievements, I can now add the dubious distinction of having come up with the syntax for the new “squiggly heredoc” introduced in version 2.3. Thus playing my part in making the Ruby grammar just a little bit more chaotic.

For reference, the syntax looks like this:

module Wonderland
  JABBERWOCKY = <<~EOF
      'Twas brillig, and the slithy toves
      Did gyre and gimble in the wabe;
      All mimsy were the borogoves,
      And the mome raths outgrabe.

    -- From "jabberwocky", by Lewis Carroll
  EOF
end

Using this syntax intelligently strips indent from the quoted string, as explained in this blog post by Damir Svrtan.

As I recall, the syntax I suggested for that feature was more or less the first thing that popped into my head. That said, it wasn't a completely arbitrary choice. There's a mnemonic reason for it, that I figure I probably ought share now that it's an official Ruby feature.

The mnemonic is this: the text quoted by a squiggly heredoc is squished, or more accurately the leading whitespace is squished, over to the left margin. Thus, the syntax is that of a "dashed heredoc", except that the dash has been squished as well, leaving it "squiggly".

I guess I should have called it the "squished heredoc" when I suggested it.

4 comments

  1. Thanks! This has long been one of my most sincere qualify items for ruby syntax, and missing it a bit of a sore thumb. It doesn’t surprise me that you were involved with it. 🙂

  2. I think your reasoning makes about much sense as the Lewis Carol quote you picked. On the other hand, it does paint an interesting picture in ones mind.

Comments are closed.