About six months ago, I watched Peter Cooper’s Ruby Trickshots and learnt that Ruby has an interesting syntax that allows you to concatenate strings by simply placing them after each other.
"foo""bar"# => "foobar"
I quickly realised that that meant that this was valid syntax:
"""foo"""# => "foo"
Which meant that Python-like docstrings were syntactically valid in Ruby!
I hacked up a bit of code that let you read out the docstring in this gist:
It was an interesting hack, but I thought that Ruby would have to evaluate the concatenation on every method invocation, hence adding a performance hit purely to add a docstring, and hence ditched the idea of taking it further, and then promptly forgot about it.
Six months later, I found it when I was going through my old gists. I brought it up with CRuby Master @charliesome, and he informed me that CRuby is pretty smart and actually won’t emit bytecode if it detects that the literals aren’t actually used, so there is actually no performance hit (apart from when it’s parsing).