Seeing code like this makes my teeth ache:

if "#{self.key}".start_with?("XYZ")



@michaelfromuk sometimes I try to understand the reasoning for that kind of code was. Sometimes the context gets lots with the churn, other it's excessive pragmatism.

In that particular case it looks like they try to avoid the infamous 'Undefined method 'starts_with?` for Nil class' and also making the sentence shorter (cool?); instead of guard it,

return false if key.nil? # blank?

or using a slower regex

if key ~= /AXYZ/

Not sure, archeology solves the mystery.

Sign in to participate in the conversation

A Mastodon instance for Rubyists & friends