require 'rubygems'
require 'recursively'
require 'facet/hash/stringify_keys'
require 'facet/hash/symbolize_keys'
require 'facet/symbol/to_proc'
# Array Example
nested = [ 'a', 'b', [ 'c', 'd', [ 'e', 'f' ] ], 'g', [ 'h' ] ]
nested.recursively!(&:upcase) # => ["A", "B", ["C", "D", ["E", "F"]], "G", ["H"]]
# Hash example
options = {
:find => {
:conditions => {
'first_name' => 'john',
:hair_color => 'brown'
},
'order' => 'last_name',
:limit => 10
},
'create' => {
:conditions => [ "hair_color = ?", 'brown' ]
}
}
options.recursively!(&:symbolize_keys)
options[:find][:conditions][:first_name] # => "john"
options.recursively!(&:stringify_keys)
options['find']['conditions']['hair_color'] # => "brown"