Inversion::

HashUtilities

module

A collection of utilities for working with Hashes.

Public Instance Methods

anchor
internify_keys( hash )
Alias for: symbolify_keys
anchor
stringify_keys( hash )

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 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
anchor
symbolify_keys( hash )

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 94
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
Also aliased as: internify_keys