Freeze Your Constants in Ruby
3 min readJan 12, 2019
Years ago, I worked on a very large Ruby on Rails codebase that used constants to hold lists of credit card transaction states. For example:
class Txn
ACTIONABLE_STATES = [:authenticated, :to_settle]
DONE_STATES = [:settled, :declined]
end
However, we had a bug where a settled transaction would return true
when txn.state.in? ACTIONABLE_STATES
was called on it.