Module: ClassyEnum::SuperClassMethods
- Defined in:
- lib/classy_enum.rb
Instance Method Summary collapse
- #all ⇒ Object
-
#all_with_name ⇒ Object
Uses the name field for select options.
-
#find(option) ⇒ Object
Alias of new.
- #new(option) ⇒ Object
- #valid_options ⇒ Object
Instance Method Details
#all ⇒ Object
33 34 35 |
# File 'lib/classy_enum.rb', line 33 def all self::OPTIONS.map {|e| self.new(e) } end |
#all_with_name ⇒ Object
Uses the name field for select options
38 39 40 |
# File 'lib/classy_enum.rb', line 38 def all_with_name self.all.map {|e| [e.name, e.to_s] } end |
#find(option) ⇒ Object
Alias of new
47 48 49 |
# File 'lib/classy_enum.rb', line 47 def find(option) new(option) end |
#new(option) ⇒ Object
29 30 31 |
# File 'lib/classy_enum.rb', line 29 def new(option) self::OPTION_HASH[option] || TypeError.new("Valid #{self} options are #{self.}") end |
#valid_options ⇒ Object
42 43 44 |
# File 'lib/classy_enum.rb', line 42 def self::OPTIONS.map(&:to_s).join(', ') end |