Class: Vorpal::Util::ArrayHash

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vorpal/util/array_hash.rb

Instance Method Summary collapse

Constructor Details

#initializeArrayHash

Returns a new instance of ArrayHash.



11
12
13
# File 'lib/vorpal/util/array_hash.rb', line 11

def initialize
  @hash = Hash.new([])
end

Instance Method Details

#append(key, values) ⇒ Object



15
16
17
18
19
20
# File 'lib/vorpal/util/array_hash.rb', line 15

def append(key, values)
  if @hash[key].nil? || @hash[key].empty?
    @hash[key] = []
  end
  @hash[key].concat(Array(values))
end

#popObject



22
23
24
25
26
# File 'lib/vorpal/util/array_hash.rb', line 22

def pop
  key = @hash.first.first
  values = @hash.delete(key)
  [key, values]
end

#valuesObject



28
29
30
# File 'lib/vorpal/util/array_hash.rb', line 28

def values
  @hash.values.flatten
end