Method: Hash#stringify_keys!
- Defined in:
- lib/core/facets/hash/symbolize_keys.rb
#stringify_keys!(&select) ⇒ Object
Destructively convert all keys to strings. This is the same as Hash#stringify_keys, but modifies the receiver in place and returns it. With a select
block, limits conversion to only certain keys.
foo = { :name=>'Gavin', :wife=>:Lisa }
foo.stringify_keys! #=> { "name"=>"Gavin", "wife"=>:Lisa }
foo #=> { "name"=>"Gavin", "wife"=>:Lisa }
This method is considered archaic. Use #rekey instead.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/core/facets/hash/symbolize_keys.rb', line 76 def stringify_keys!(&select) if select keys.each do |key| if select[key] self[key.to_s] = delete(key) end end else keys.each do |key| self[key.to_s] = delete(key) end end self end |