From 92dbdb2340839f5d21b467eb68675f597fa3a588 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 13 May 2012 12:49:15 -0500 Subject: added example to Hash#symbolize_keys --- activesupport/lib/active_support/core_ext/hash/keys.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 057fff05e3..81ee71d5fb 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -1,7 +1,7 @@ class Hash # Return a new hash with all keys converted to strings. # - # { :name => 'Rob', :years => '28' }.stringify_keys + # { name: 'Rob', years: '28' }.stringify_keys # #=> { "name" => "Rob", "years" => "28" } def stringify_keys result = {} @@ -22,6 +22,9 @@ class Hash # Return a new hash with all keys converted to symbols, as long as # they respond to +to_sym+. + # + # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys + # #=> { :name => "Rob", :years => "28" } def symbolize_keys result = {} keys.each do |key| @@ -32,7 +35,7 @@ class Hash alias_method :to_options, :symbolize_keys # Destructively convert all keys to symbols, as long as they respond - # to +to_sym+. + # to +to_sym+. Same as +symbolize_keys+, but modifies self. def symbolize_keys! keys.each do |key| self[(key.to_sym rescue key)] = delete(key) -- cgit v1.2.3