Class: Hash

Inherits:
Object show all
Defined in:
lib/aromat/dclone.rb,
lib/aromat/str_keys.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



37
38
39
# File 'lib/aromat/dclone.rb', line 37

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

#str_keysHash

Stringize Keys: Recursively stringizes hash keys.

Returns:

  • (Hash)

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



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

def str_keys
	Hash[*(inject([]) { |a, e| (a << (e[0].is_a?(Symbol) ? e[0].to_s : e[0])) << (e[1].respond_to?(:str_keys) ? e[1].str_keys : e[1]) })]
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