Four Key Reasons to Learn Markdown
Back-End Leveling UpWriting documentation is fun—really, really fun. I know some engineers may disagree with me, but as a technical writer, creating quality documentation that will...
I’ve often felt like Ruby Regexp captures are a bit clumsy.
Let’s say we need to break apart phone numbers:
After executing this match, we might do something like this with the parsed number:
What’s up with the dollar signs and the sequential numbers?
I feel like I’m writing assembly code and referring to registers or memory offsets or something.
If I’m a new Ruby programmer reading this code, I might have no idea what is going on here.
We can do better if we upgrade from magical variables to the Regexp.last_match method:
At least this is a bit more readable than the magic variables.
And it’s probably easier for a newcomer to find documentation for Regexp.last_match than $1.
But there’s an even better way in Ruby 1.9 – named captures:
Now we’ve got readable code, and better documentation built into our regular expression.
Are you using Ruby 1.9 yet? If so, have you had a chance to use named captures?
Writing documentation is fun—really, really fun. I know some engineers may disagree with me, but as a technical writer, creating quality documentation that will...
Humanity has come a long way in its technological journey. We have reached the cusp of an age in which the concepts we have...
Go 1.18 has finally landed, and with it comes its own flavor of generics. In a previous post, we went over the accepted proposal and dove...