Module: DataTools::HashOfArrays
- Defined in:
- lib/data_tools/hash_of_arrays.rb
Overview
keys can be anything values are always arrays
Instance Method Summary collapse
Instance Method Details
#append(hash2) ⇒ Object
5 6 7 |
# File 'lib/data_tools/hash_of_arrays.rb', line 5 def append(hash2) (self.keys | hash2.keys).inject({}) {|h,k| h[k] = Array(self[k]) + Array(hash2[k]); h} end |
#choose ⇒ Object
15 16 17 18 19 |
# File 'lib/data_tools/hash_of_arrays.rb', line 15 def choose each_with_object({}) do |(key, values), result| result[key] = yield values end end |
#coalesce(key1, args) ⇒ Object
9 10 11 12 13 |
# File 'lib/data_tools/hash_of_arrays.rb', line 9 def coalesce(key1, args) key2 = args[:into] or raise "usage: coalesce(key1, :into => key)" self[key2] += self[key1] delete(key1) end |