Remember how I thought that the syntax for single-quoted heredocs was weird? I’ve got something even weirder for you today!

Turns out that when using single-quoted heredoc delimiters you can have pretty much anything in them, including spaces!

<<'END HTML'
  <html>
    ...
  </html>
END HTML

<<'\n!"£$%^&*()-=_+[];#{}:@~,./<>?|`\'
hello
\n!"£$%^&*()-=_+[];#{}:@~,./<>?|`\

It never crossed my mind that something like this would be possible until I came across this RuboCop ticket, asking for spaces in delimiters to be allowed. As most editors are unlikely to handle this properly1, and it looks pretty… weird, I think that you should restrain yourselves from using such heredoc delimiters.

That’s all I have for you today. Keep Ruby Weird!

Articles in the Series

  1. Clearly rouge (the code highlighter my blog uses) doesn’t handle such delimiters properly as well.