Class: HashMath::Matrix::KeyValuePair

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_math/matrix/key_value_pair.rb

Overview

A hash-like structure that allows you to gradually build up keys.

Defined Under Namespace

Classes: Pair

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ KeyValuePair

Returns a new instance of KeyValuePair.



18
19
20
21
22
23
# File 'lib/hash_math/matrix/key_value_pair.rb', line 18

def initialize(key)
  @key    = key
  @value  = Set.new

  freeze
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



16
17
18
# File 'lib/hash_math/matrix/key_value_pair.rb', line 16

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



16
17
18
# File 'lib/hash_math/matrix/key_value_pair.rb', line 16

def value
  @value
end

Instance Method Details

#add(val) ⇒ Object



29
30
31
# File 'lib/hash_math/matrix/key_value_pair.rb', line 29

def add(val)
  tap { value << val }
end

#add_each(vals) ⇒ Object



25
26
27
# File 'lib/hash_math/matrix/key_value_pair.rb', line 25

def add_each(vals)
  tap { vals.each { |val| add(val) } }
end

#pairsObject



33
34
35
# File 'lib/hash_math/matrix/key_value_pair.rb', line 33

def pairs
  value.map { |value| Pair.new(key, value) }
end