Class: Darthjee::CoreExt::Hash::KeysSorter

Inherits:
Object
  • Object
show all
Defined in:
lib/darthjee/core_ext/hash/keys_sorter.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash, recursive: true) ⇒ KeysSorter

Returns a new instance of KeysSorter.



7
8
9
10
# File 'lib/darthjee/core_ext/hash/keys_sorter.rb', line 7

def initialize(hash, recursive: true)
  @hash = hash
  @recursive = recursive
end

Instance Method Details

#sortObject



12
13
14
15
16
17
18
# File 'lib/darthjee/core_ext/hash/keys_sorter.rb', line 12

def sort
  {}.tap do |new_hash|
    sorted_keys.each do |key|
      new_hash[key] = change_value(hash[key])
    end
  end
end