Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/aromat/dclone.rb,
lib/aromat/sym_keys.rb

Overview

Monkey-patch Hash Class

Instance Method Summary collapse

Instance Method Details

#dcloneHash

Deep-Clone Recursively clones every level of the Hash

Returns:

  • (Hash)

    A copy of the original hash where each element has been clone’d



34
35
36
# File 'lib/aromat/dclone.rb', line 34

def dclone
  Hash[*(inject([]) { |a, e| a + e }.collect { |e| e.respond_to?(:dclone) ? e.dclone : Aromat::Dclone.base_clone(e) })]
end

#sym_keysHash

Symbolize Keys Recursively symbolizes hash keys

Returns:

  • (Hash)

    A copy of the original hash where each element has had its keys recursively symbolized



21
22
23
# File 'lib/aromat/sym_keys.rb', line 21

def sym_keys
  Hash[*(inject([]) { |a, e| (a << (e[0].respond_to?(:to_sym) ? e[0].to_sym : e[0])) << (e[1].respond_to?(:sym_keys) ? e[1].sym_keys : e[1]) })]
end