Module: Inversion::HashUtilities
- Included in:
- Template::ConfigTag
- Defined in:
- lib/inversion/mixins.rb
Overview
A collection of utilities for working with Hashes.
Class Method Summary collapse
-
.stringify_keys(hash) ⇒ Object
Return a version of the given ‘hash` with its keys transformed into Strings from whatever they were before.
-
.symbolify_keys(hash) ⇒ Object
(also: internify_keys)
Return a duplicate of the given ‘hash` with its identifier-like keys transformed into symbols from whatever they were before.
Class Method Details
.stringify_keys(hash) ⇒ Object
Return a version of the given ‘hash` with its keys transformed into Strings from whatever they were before.
stringhash = stringify_keys( symbolhash )
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/inversion/mixins.rb', line 74 def stringify_keys( hash ) newhash = {} hash.each do |key,val| if val.is_a?( Hash ) newhash[ key.to_s ] = stringify_keys( val ) else newhash[ key.to_s ] = val end end return newhash end |
.symbolify_keys(hash) ⇒ Object Also known as: internify_keys
Return a duplicate of the given ‘hash` with its identifier-like keys transformed into symbols from whatever they were before.
symbolhash = symbolify_keys( stringhash )
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/inversion/mixins.rb', line 94 def symbolify_keys( hash ) newhash = {} hash.each do |key,val| keysym = key.to_s.to_sym if val.is_a?( Hash ) newhash[ keysym ] = symbolify_keys( val ) else newhash[ keysym ] = val end end return newhash end |