Module: Abstractivator::Sort

Defined in:
lib/abstractivator/sort.rb

Instance Method Summary collapse

Instance Method Details

#deep_sort_hash(obj) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/abstractivator/sort.rb', line 3

def deep_sort_hash(obj)
  case obj
  when Hash
    obj.sort.each_with_object({}) do |(k, v), a|
      a[k] = deep_sort_hash(v)
    end
  when Array
    obj.map(&method(:deep_sort_hash))
  else
    obj
  end
end