Ruby already solved my problem š
One great question in office hours led me to delete a whole class.
Yesterday I hosted Novemberās Hotwire Native Office Hours.
Every month I host an hour long Zoom session for developers to directly ask me questions. The topics range greatly: some folks are just getting started and others are asking very specific, advanced questions.
This month we covered everything from registering bridge components to native vs. web-based tabs to authenticating Apple Watch apps! Itās really fun to see what folks are working on in the Hotwire Native space.
During the session I shared some code I wrote to figure out what version a Hotwire Native app is running. The app sends the version in the user agent (e.g. v1.2.3) and then I parse it with the following Ruby class on the server:
class AppVersion
include Comparable
attr_reader :major, :minor, :patch
def initialize(version_string)
parts = version_string.to_s.split(ā.ā).map(&:to_i)
@major, @minor, @patch = parts[0] || 0, parts[1] || 0, parts[2] || 0
end
def <=>(other)
[major, minor, patch] <=> [other.major, other.minor, other.patch]
end
def to_s
ā#{major}.#{minor}.#{patch}ā
end
endAnd it works great! I use this throughout my apps to feature flag code based on which version the app is running.
But someone brought up something even better: Gem::Version. This class accomplishes the same goal: āprocess string versions into comparable valuesā.
irb(main)> Gem::Version.new("1.2.3") > Gem::Version.new("1.2.2")
=> true
irb(main)> Gem::Version.new("2.0") > Gem::Version.new("1.2.2")
=> trueIt can even compare prerelease versions, like alphas or betas.
irb(main)> Gem::Version.new("2.0.b1") > Gem::Version.new("1.9")
=> true
irb(main)> Gem::Version.new("2.0") > Gem::Version.new("2.0.b1")
=> trueThe big advantage this class has over my implementation is that itās built into Ruby!
Itās not even a Rails dependency but part of the standard Ruby library. Internally, this class is used to compare version numbers when parsing your Gemfile. Check out the documentation, I picked up a few things on semantic versioning when reading it.
Iāve already replaced my AppVersion class with Gem::Version. But it makes me wonder what other Ruby/Rails features I donāt know about and am implementing on my own!
The power of community, no matter how small
I never would have learned about Gem::Version if it wasnāt for someone bringing it up during office hours. Iād still be using my custom (and most likely buggy!) AppVersion implementationā¦Ā like a chump. š
But seriously, this is why I love connecting with folks in the Ruby/Rails community. Every time I go to an event, host a workshop, give a talkā¦Ā I learn something new. Sometimes itās small things like Gem::Version. Other times it completely changes my career, like the first time I heard about Hotwire Native.
Iāve taken this to heart and recently started organizing monthly Coffee and Code coworking sessions in my city, Portland, OR. Every month I post up at a local coffee shop with my laptop and invite all of the Portland Ruby Brigade to join.
This month we had five people! Itās no corporate-sponsored-meetup but it sure is something. And the connections that folks are making during these casual events are real. Iāve already seen folks exchange emails for potential future contract gigs.
Whatās the first step you can take today to build some community in your local area? Even if it is just finally inviting that connection-to-be for a beverage⦠I say go for it.
If you want to join next monthās office hours then consider becoming a paid subscriber of my newsletter. I hope to see you there! š
Hotwire Native Office Hours
Every month I host an hour-long Zoom session for Hotwire Native developers to ask questions, share progress, and connect with others building the same way.



