class ContractedValue::AttributeSet

Attributes

attributes_hash[R]

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/contracted_value/core.rb, line 91
def self.new(*)
  ::IceNine.deep_freeze(super)
end
new(attributes_hash = {}) click to toggle source
# File lib/contracted_value/core.rb, line 95
def initialize(attributes_hash = {})
  @attributes_hash = attributes_hash
end

Public Instance Methods

add(attr) click to toggle source
# File lib/contracted_value/core.rb, line 103
def add(attr)
  merge!(self.class.new(attr.name => attr))
end
each_attribute() { |v| ... } click to toggle source
# 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) click to toggle source
# 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

Protected Instance Methods

attr_names() click to toggle source
# File lib/contracted_value/core.rb, line 126
def attr_names
  @attributes_hash.keys
end
merge!(other_attr_set) click to toggle source
# File lib/contracted_value/core.rb, line 117
def merge!(other_attr_set)
  shared_keys = attr_names & other_attr_set.attr_names
  if shared_keys.any?
    raise(Errors::DuplicateAttributeDeclaration, shared_keys.first)
  end

  self.class.new(attributes_hash.merge(other_attr_set.attributes_hash))
end