Class: Amaranth::Collection
- Inherits:
-
Object
- Object
- Amaranth::Collection
- Defined in:
- lib/amaranth/collection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attributes ⇒ Object (also: #to_h)
- #attributes=(attributes) ⇒ Object
-
#initialize(attributes = {}) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(attributes = {}) ⇒ Collection
Returns a new instance of Collection.
23 24 25 |
# File 'lib/amaranth/collection.rb', line 23 def initialize attributes={} self.attributes = attributes end |
Class Method Details
.field(key) ⇒ Object
13 14 15 16 17 |
# File 'lib/amaranth/collection.rb', line 13 def self.field key @fields ||= [] @fields << key attr_accessor key end |
.fields ⇒ Object
19 20 21 |
# File 'lib/amaranth/collection.rb', line 19 def self.fields @fields end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 |
# File 'lib/amaranth/collection.rb', line 33 def == other self.attributes == other.attributes end |
#attributes ⇒ Object Also known as: to_h
37 38 39 40 41 |
# File 'lib/amaranth/collection.rb', line 37 def attributes self.class.fields.reduce({}) do |attrs, key| attrs.merge key => send(key) end end |
#attributes=(attributes) ⇒ Object
27 28 29 30 31 |
# File 'lib/amaranth/collection.rb', line 27 def attributes= attributes attributes.each do |key, value| send :"#{key}=", value end end |