Welcome to the Lapidary Lemur Mailing List! A recurring Ruby rundown from the mind of Brandon Weaver (@keystonelemur) about what he’s been working on, reading, thinking about, and shipping.
What I’ve written or shipped lately
A new series on fundamental and foundational concepts in programming Ruby, meant as a more introductory text. Frequently I find myself hunting down references on specific subjects to hand to those I’m teaching, and this series reflects the more frequent topics I’ve seen brought up.
Current posts out are:
The next posts that I have planned will cover Enumerable, Classes, Modules, Set, Struct, YARDoc, Methods, and a few other subjects, but not necessarily in that order.
My previous newsletter mentioned a fairly extensive document on Pattern Matching Interfaces in Ruby. It didn’t get quite as much traction as I would have liked, so we’re breaking it into a series of posts on Pattern Matching to go into even more depth. The goal of this series is to be a comprehensive and definitive guide to Pattern Matching in Ruby.
Current posts are:
The next posts will cover Hash-like Structures, Best Practices, and a set of more pragmatic examples to show how you might use this in the real world.
…but if we’re going to talk about practical examples, let’s take a look at a quick one:
def roman_numeral(n) = case n in 1000..3000 then 'M' + roman_numeral(n - 1000) in 900.. then 'CM' + roman_numeral(n - 900) in 500.. then 'D' + roman_numeral(n - 500) in 400.. then 'CD' + roman_numeral(n - 400) in 100.. then 'C' + roman_numeral(n - 100) in 90.. then 'XC' + roman_numeral(n - 90) in 50.. then 'L' + roman_numeral(n - 50) in 40.. then 'XL' + roman_numeral(n - 40) in 10.. then 'X' + roman_numeral(n - 10) in 9 then 'IX' + roman_numeral(n - 9) in 5.. then 'V' + roman_numeral(n - 5) in 4 then 'IV' + roman_numeral(n - 4) in 1.. then 'I' + roman_numeral(n - 1) else '' end
Endless ranges are a beautiful thing with case statement cascades. Could this use
where? Sure, but
in is shorter and will do the same thing in this case. This is also admittedly a case where I’d argue for method-level Pattern Matching.
Books, articles, tutorials, and other content I’ve been reading lately
By Ryan Gordon
DragonRuby is really quite interesting, and I keep meaning to give it a try. For now I’ll enjoy watching a few videos here and there until an idea strikes.
By Denise Yu
A lovely Twitter thread on being a more Senior IC that boils down to “In every conversation you’re part of, create clarity and reduce chaos.” Great insights here.
Musings, what I’m planning next, and what’s to come
RailsConf’s CFP is open, and I’ll be on the program committee this year. I’d love to read all of your submissions!
I’ve been reading and watching a lot more Elixir tutorials on Pattern Matching to get ideas on more practical examples I can share with the community. With any new feature it takes time to develop an intuition on when and where to use it, and the Ruby community will need a bit to get there.
Along with the interface document I wrote last week I still intend to implement Pattern Matching interfaces across a good subset of Ruby, and could definitely use some help doing so.
“Definitive Pattern Matching” is one effort to raise awareness and get the conversation going.