Enums in Rails are relatively new, but also incredibly useful. When we create an enum, we get lots of other things that come along with that for free. Consider this example from PATS Medicine
model:
enum :admin_method, { oral: 1, injection: 2, intravenous: 3, topical: 4}, scopes: true
When I create this, because I have specified scopes: true
, I automatically get scopes written for Medicine.oral
, Medicine.injection
, Medicine.intravenous
, and Medicine.topical
. I still need to test these methods to be sure they were created as intended, but I have confidence that they will work and help us filter medicines by the appropriate admin_method.