class Creature < ApplicationRecord scope :alive, -> { where('health_points > 0') } enum :size, [:small, :big, :giant] def to_label "#{name} (#{health_points})" end before_create do self.size = case health_points when 0..10 :small when 11..30 :big else :giant end end end