Class: Stunted::HashArray

Inherits:
Array
  • Object
show all
Extended by:
ShapeableClassMethods
Includes:
Shapeable
Defined in:
lib/stunted/hash-array.rb

Instance Method Summary collapse

Methods included from ShapeableClassMethods

shaped_class

Methods included from Shapeable

#become

Instance Method Details

#collapse_and_aggregate(*keys) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/stunted/hash-array.rb', line 6

def collapse_and_aggregate(*keys)
  keys.reduce(first) do | accumulator, key |
    collection = collect(&key)
    collection = yield(collection) if block_given?
    accumulator.merge(key => collection)
  end
end

#segregate_by_key(key) ⇒ Object



14
15
16
17
18
# File 'lib/stunted/hash-array.rb', line 14

def segregate_by_key(key)
  group_by(&key).values.collect do | inner | 
    self.class.new(inner)
  end
end