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
- #detect_unexpected_keys(hash) ⇒ 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.
105 106 107 |
# File 'lib/contracted_value/core.rb', line 105 def initialize(attributes_hash = {}) @attributes_hash = attributes_hash end |
Class Method Details
.new ⇒ Object
101 102 103 |
# File 'lib/contracted_value/core.rb', line 101 def self.new(*) ::IceNine.deep_freeze(super) end |
Instance Method Details
#add(attr) ⇒ Object
113 114 115 |
# File 'lib/contracted_value/core.rb', line 113 def add(attr) merge!(self.class.new(attr.name => attr)) end |
#detect_unexpected_keys(hash) ⇒ Object
125 126 127 |
# File 'lib/contracted_value/core.rb', line 125 def detect_unexpected_keys(hash) hash.keys - attr_names end |
#each_attribute ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/contracted_value/core.rb', line 117 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
109 110 111 |
# File 'lib/contracted_value/core.rb', line 109 def merge(other_attr_set) self.class.new(attributes_hash.merge(other_attr_set.attributes_hash)) end |