A collection of utilities for working with Hashes.
Return a version of the given hash with its keys transformed into Strings from whatever they were before.
stringhash = stringify_keys( symbolhash )
# File lib/inversion/mixins.rb, line 151 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
Return a duplicate of the given hash with its identifier-like keys untainted and transformed into symbols from whatever they were before.
symbolhash = symbolify_keys( stringhash )
# File lib/inversion/mixins.rb, line 171 def symbolify_keys( hash ) newhash = {} hash.each do |key,val| keysym = key.to_s.dup.untaint.to_sym if val.is_a?( Hash ) newhash[ keysym ] = symbolify_keys( val ) else newhash[ keysym ] = val end end return newhash end
Generated with the Darkfish Rdoc Generator 2.