Class: ContractedValue::AttributeSet
- Inherits:
-
Object
- Object
- ContractedValue::AttributeSet
- Defined in:
- lib/contracted_value/core.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(attr) ⇒ Object
- #each_attribute ⇒ Object
-
#initialize(attributes_hash = {}) ⇒ AttributeSet
constructor
A new instance of AttributeSet.
- #merge(other_attr_set) ⇒ Object
Constructor Details
#initialize(attributes_hash = {}) ⇒ AttributeSet
Returns a new instance of AttributeSet.
95 96 97 |
# File 'lib/contracted_value/core.rb', line 95 def initialize(attributes_hash = {}) @attributes_hash = attributes_hash end |
Class Method Details
.new ⇒ Object
91 92 93 |
# File 'lib/contracted_value/core.rb', line 91 def self.new(*) ::IceNine.deep_freeze(super) end |
Instance Method Details
#add(attr) ⇒ Object
103 104 105 |
# File 'lib/contracted_value/core.rb', line 103 def add(attr) merge!(self.class.new(attr.name => attr)) end |
#each_attribute ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/contracted_value/core.rb', line 107 def each_attribute return to_enum(:each_attribute) unless block_given? attributes_hash.each_value do |v| yield(v) end end |
#merge(other_attr_set) ⇒ Object
99 100 101 |
# File 'lib/contracted_value/core.rb', line 99 def merge(other_attr_set) self.class.new(attributes_hash.merge(other_attr_set.attributes_hash)) end |