Module: ClassyEnum::ClassMethods
- 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
30 31 32 |
# File 'lib/classy_enum.rb', line 30 def all self::OPTIONS.map {|e| self.new(e) } end |
#all_with_name ⇒ Object
Uses the name field for select options
35 36 37 |
# File 'lib/classy_enum.rb', line 35 def all_with_name self.all.map {|e| [e.name, e.to_s] } end |
#find(option) ⇒ Object
Alias of new
44 45 46 |
# File 'lib/classy_enum.rb', line 44 def find(option) new(option) end |
#new(option) ⇒ Object
26 27 28 |
# File 'lib/classy_enum.rb', line 26 def new(option) self::OPTION_HASH[option] || TypeError.new("Valid #{self} options are #{self.}") end |
#valid_options ⇒ Object
39 40 41 |
# File 'lib/classy_enum.rb', line 39 def self::OPTIONS.map(&:to_s).join(', ') end |