Inversion::

HashUtilities module

A collection of utilities for working with Hashes.

Public Instance Methods

internify_keys( hash )
Alias for: symbolify_keys
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 73
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 )

Return a duplicate of the given ‘hash` with its identifier-like keys transformed into symbols from whatever they were before.

symbolhash = symbolify_keys( stringhash )
# File lib/inversion/mixins.rb, line 93
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
Also aliased as: internify_keys