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 )
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/inversion/mixins.rb', line 75 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 )
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/inversion/mixins.rb', line 95 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 |