Created
September 13, 2018 09:13
-
-
Save bitsapien/cfe511c756bb7640a6a0057b1bec3d44 to your computer and use it in GitHub Desktop.
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 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