Sha256: b4345d7dc9ed53b5505b5061cd3a223dd37ada43e2e042230a425df15c129366
Contents?: true
Size: 581 Bytes
Versions: 25
Compression:
Stored size: 581 Bytes
Contents
module JSONAPIonify module DeepSortCollection refine Array do def deep_sort(hash) keys = hash.to_a sorter = lambda do |iterator, depth = 0| key_name, order = keys[depth] if key_name sorted = iterator.sort_by(&key_name) sorted.reverse! if order == :desc sorted.group_by(&key_name).values.map do |value| sorter.call(value, depth + 1) end.reduce(:+) || [] else iterator end end sorter.call(self) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems