Module: Configurability::Config::DataUtilities
- Included in:
- Configurability::Config, Struct
- Defined in:
- lib/configurability/config.rb
Overview
A collection of data-structure-manipulation functions. :TODO: Replace with #transform_keys after 2.4’s EOL
Instance Method Summary collapse
-
#stringify_keys(hash) ⇒ Object
Return a version of the given
hashwith its keys transformed into Strings from whatever they were before. -
#symbolify_keys(hash) ⇒ Object
Return a duplicate of the given
hashwith its identifier-like keys transformed into symbols from whatever they were before.
Instance Method Details
#stringify_keys(hash) ⇒ Object
Return a version of the given hash with its keys transformed into Strings from whatever they were before.
315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/configurability/config.rb', line 315 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
Return a duplicate of the given hash with its identifier-like keys transformed into symbols from whatever they were before.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/configurability/config.rb', line 297 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 |