Class: Vorpal::Util::ArrayHash
- Inherits:
-
Object
- Object
- Vorpal::Util::ArrayHash
- Extended by:
- Forwardable
- Defined in:
- lib/vorpal/util/array_hash.rb
Instance Method Summary collapse
- #append(key, values) ⇒ Object
-
#initialize ⇒ ArrayHash
constructor
A new instance of ArrayHash.
- #pop ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ ArrayHash
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 |
#pop ⇒ Object
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 |
#values ⇒ Object
28 29 30 |
# File 'lib/vorpal/util/array_hash.rb', line 28 def values @hash.values.flatten end |