You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
345 B

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