aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-13 12:49:15 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-13 12:49:15 -0500
commit92dbdb2340839f5d21b467eb68675f597fa3a588 (patch)
treef853d3b18621188e0cd09926a073523bf3131104 /activesupport/lib/active_support/core_ext/hash
parent817f9e64ee4e5b02efd9b4047c23340bf4b75586 (diff)
downloadrails-92dbdb2340839f5d21b467eb68675f597fa3a588.tar.gz
rails-92dbdb2340839f5d21b467eb68675f597fa3a588.tar.bz2
rails-92dbdb2340839f5d21b467eb68675f597fa3a588.zip
added example to Hash#symbolize_keys
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/keys.rb7
1 files 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)