-
-
Save vitalyrotari/d78ea37835166fc3959c to your computer and use it in GitHub Desktop.
Ruby Enum example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Photo < ActiveRecord::Base | |
module Statues | |
QUEUED = 'queued' | |
NEW = 'new' | |
def self.values | |
constants.map(&method(:const_get)) | |
end | |
# you can define more special methods as you wanted for Statues | |
end | |
validates :status, inclusion: {in: Statues.values } | |
def change_status | |
self.status = Statues::NEW | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment