Configurability::Config::
DataUtilities
module
A collection of data-structure-manipulation functions. :todo: Replace with transform_keys after 2.4’s EOL
Return a version of the given hash
with its keys transformed into Strings from whatever they were before.
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 transformed into symbols from whatever they were before.
def symbolify_keys( hash )
newhash = {}
hash.each do |key,val|
key = key.to_sym if key.respond_to?( :to_sym )
if val.is_a?( Hash )
newhash[ key ] = symbolify_keys( val )
else
newhash[ key ] = val
end
end
return newhash
end