Musings of a Gotham City Geek

What is the sound of one blog clapping?

 

A Ruby in the Rough - Use any character as a string delimiter

I intuitively knew this, I think, regarding here docs, but just seeing it again caused me to be taken aback. You just don’t see this used quite that often. Makes it nice in strings that you want to use interpolation and double-quotes without having to escape the double-quotes.

Ruby allows you to define any character you want as a string delimiter simply by prefixing the desired character with a %. For example, we could use the ampersand to delimit our string:

myString = %&This is my String&

Blog comments powered by Disqus