Skip to content

Instantly share code, notes, and snippets.

@bitsapien
Created September 13, 2018 09:13
Show Gist options
  • Save bitsapien/cfe511c756bb7640a6a0057b1bec3d44 to your computer and use it in GitHub Desktop.
Save bitsapien/cfe511c756bb7640a6a0057b1bec3d44 to your computer and use it in GitHub Desktop.
class Life < ApplicationRecord
RACES = [
"Time Lord",
"Earthling",
"Dalek"
]
# constants for easy access, the race_key method is not available in this context
RACES.each do |race|
const_set(race_key(race), race)
# Life::TIME_LORD = "Time Lord"
# Life::DALEK = "Dalek"
end
def self.race_key(race)
race.paramterize.underscore.upcase
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment