Module: Enumerable
- Defined in:
- lib/html-native/collections.rb
Instance Method Summary collapse
-
#component_map ⇒ Object
Maps the given block to each element of enum.
-
#to_ol(attributes: {}) ⇒ Object
Returns an OrderedListComponent representing the enum.
-
#to_ul(attributes: {}) ⇒ Object
Returns an UnorderedListComponent representing the enum.
Instance Method Details
#component_map ⇒ Object
Maps the given block to each element of enum. The result of each iteration is added to an HTMLComponent::Builder instance, which is returned after the final iteration.
If no block is given, an enumerator is returned instead.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/html-native/collections.rb', line 10 def component_map if block_given? result = HTMLComponent::Builder.new each do |e| result += yield(e) end result else to_enum(:component_map) end end |
#to_ol(attributes: {}) ⇒ Object
Returns an OrderedListComponent representing the enum.
See OrderedListComponent#new for details on how to apply attributes.
25 26 27 |
# File 'lib/html-native/collections.rb', line 25 def to_ol(attributes: {}) OrderedListComponent.new(self, attributes: attributes) end |
#to_ul(attributes: {}) ⇒ Object
Returns an UnorderedListComponent representing the enum.
See UnorderedListComponent#new for details on how to apply attributes.
32 33 34 |
# File 'lib/html-native/collections.rb', line 32 def to_ul(attributes: {}) UnorderedListComponent.new(self, attributes: attributes) end |