Module: ClassyEnum::Collection::ClassMethods
- Defined in:
- lib/classy_enum/collection.rb
Instance Method Summary collapse
-
#all ⇒ Object
Returns an array of all instantiated enums.
- #inherited(klass) ⇒ Object
-
#select_options ⇒ Object
Returns a 2D array for Rails select helper options.
Instance Method Details
#all ⇒ Object
Returns an array of all instantiated enums
Example
# Create an Enum with some elements
class Priority < ClassyEnum::Base
end
class Priority::Low < Priority; end
class Priority::Medium < Priority; end
class Priority::High < Priority; end
Priority.all # => [Priority::Low.new, Priority::Medium.new, Priority::High.new]
54 55 56 |
# File 'lib/classy_enum/collection.rb', line 54 def all .map(&:new) end |
#inherited(klass) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/classy_enum/collection.rb', line 30 def inherited(klass) if self == ClassyEnum::Base klass.class_attribute :enum_options klass. = [] else << klass klass.instance_variable_set('@index', .size) end super end |
#select_options ⇒ Object
Returns a 2D array for Rails select helper options. Also used internally for Formtastic support
Example
# Create an Enum with some elements
class Priority < ClassyEnum::Base
end
class Priority::Low < Priority; end
class Priority::ReallyHigh < Priority; end
Priority. # => [["Low", "low"], ["Really High", "really_high"]]
70 71 72 |
# File 'lib/classy_enum/collection.rb', line 70 def all.map {|e| [e.to_s.titleize, e.to_s] } end |