Module: Enum::ClassMethods
- Defined in:
- lib/abstractivator/enum.rb
Instance Method Summary collapse
Instance Method Details
#from(x) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/abstractivator/enum.rb', line 43 def from(x) if x.is_a?(Enum) x else values.find{|v| v.value == x} end end |
#from_symbol(sym) ⇒ Object
39 40 41 |
# File 'lib/abstractivator/enum.rb', line 39 def from_symbol(sym) safe_constantize("#{name}::#{sym.to_s.upcase}") end |
#name_for(value) ⇒ Object
35 36 37 |
# File 'lib/abstractivator/enum.rb', line 35 def name_for(value) constants.detect{|sym| const_get(sym) == value} end |
#values ⇒ Object
31 32 33 |
# File 'lib/abstractivator/enum.rb', line 31 def values constants.map{|sym| const_get(sym)}.reject{|x| x == Enum::ClassMethods} end |