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:

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.

Published by Avdi Grimm

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. 🙂

    Reply
  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.

    Reply
  3. […] 2.3 adds the new squiggly heredoc syntax which will be useful in this case as it prevents unnecessary leading whitespace. Adding it […]

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *