Skip to content

Instantly share code, notes, and snippets.

@rjregenold
Created November 9, 2012 20:35
Show Gist options
  • Save rjregenold/4048072 to your computer and use it in GitHub Desktop.
Save rjregenold/4048072 to your computer and use it in GitHub Desktop.
def recurse_grouping(grouping, by, f, grouped_values = {})
key = by.shift
grouping.map do |name,group|
grouped_values[key] = name
if by.empty?
data = group.data.first.to_hash.merge(grouped_values)
f.call(group, data)
else
recurse_grouping(grouping / name, by.dup, f, grouped_values.dup)
end
end.flatten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment