Consider using Sorbet
Opened this issue · 1 comments
movermeyer commented
Sorbet is a gradual typing system.
Consider typing ruby-cldr
using Sorbet to help catch typing bugs?
movermeyer commented
Aside: There was a suggestion that if we wanted to tie ourselves to Sorbet, that we could use it's Enum
to implement DraftStatus
in a slightly different way:
# typed: strict
class Status < T::Enum
extend T::Sig
enums do
Unconfirmed = new
Provisional = new
Contributed = new
Approved = new
end
sig { returns(Integer) }
def to_i
case self
when Unconfirmed then 1
when Provisional then 2
when Contributed then 3
when Approved then 4
else T.absurd(self)
end
end
sig { params(other: Status).returns(Integer) }
def <=>(other)
to_i <=> other.to_i
end
sig { params(name: String).returns(Status) }
def self.fetch(name)
case name
when 'unconfirmed' then Unconfirmed
when 'provisional' then Provisional
when 'contributed' then Contributed
when 'approved' then Approved
else
raise ArgumentError, "invalid status: #{name}"
end
end
end
That way it can do some fun things like completeness checks on case
statements.
(I'm not sure that it's worth the dependency though)