Class: FormObj::Struct::Attributes
- Inherits:
-
Object
- Object
- FormObj::Struct::Attributes
- Defined in:
- lib/form_obj/struct/attributes.rb
Direct Known Subclasses
Instance Method Summary collapse
- #add(attribute) ⇒ Object
-
#initialize(items = []) ⇒ Attributes
constructor
A new instance of Attributes.
- #map(*args, &block) ⇒ Object
Constructor Details
#initialize(items = []) ⇒ Attributes
Returns a new instance of Attributes.
4 5 6 |
# File 'lib/form_obj/struct/attributes.rb', line 4 def initialize(items = []) @items = items end |
Instance Method Details
#add(attribute) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/form_obj/struct/attributes.rb', line 8 def add(attribute) if @items.map(&:name).include? attribute.name self.class.new(@items.map { |item| item.name == attribute.name ? attribute : item }) else self.class.new(@items + [attribute]) end end |
#map(*args, &block) ⇒ Object
16 17 18 |
# File 'lib/form_obj/struct/attributes.rb', line 16 def map(*args, &block) @items.map(*args, &block) end |