aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorHendy Tanata <htanata@gmail.com>2014-02-27 19:31:08 -0800
committerHendy Tanata <htanata@gmail.com>2014-02-27 19:55:08 -0800
commit42417b0013819e573be9ffc5402e179003156e8e (patch)
treeb0dd4260ddb9ce5e0928dfa74c49b877bf58550f /guides
parentf302079d97b5c139b56f1acd2d516be52351c4fe (diff)
downloadrails-42417b0013819e573be9ffc5402e179003156e8e.tar.gz
rails-42417b0013819e573be9ffc5402e179003156e8e.tar.bz2
rails-42417b0013819e573be9ffc5402e179003156e8e.zip
Improve guide for Hash#transform_keys and related methods.
[skip ci]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_support_core_extensions.md21
1 files changed, 15 insertions, 6 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 2ad09f599b..7e6cda4b26 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -2719,11 +2719,14 @@ The method `transform_keys` accepts a block and returns a hash that has applied
# => {"" => nil, "A" => :a, "1" => 1}
```
-The result in case of collision is undefined:
+The result in case of key collision is not guaranteed:
```ruby
{"a" => 1, a: 2}.transform_keys { |key| key.to_s.upcase }
-# => {"A" => 2}, in my test, can't rely on this result though
+# The result could either be
+# => {"A"=>2}
+# or
+# => {"A"=>1}
```
This method may be useful for example to build specialized conversions. For instance `stringify_keys` and `symbolize_keys` use `transform_keys` to perform their key conversions:
@@ -2758,11 +2761,14 @@ The method `stringify_keys` returns a hash that has a stringified version of the
# => {"" => nil, "a" => :a, "1" => 1}
```
-The result in case of collision is undefined:
+The result in case of key collision is not guaranteed:
```ruby
{"a" => 1, a: 2}.stringify_keys
-# => {"a" => 2}, in my test, can't rely on this result though
+# The result could either be
+# => {"a"=>2}
+# or
+# => {"a"=>1}
```
This method may be useful for example to easily accept both symbols and strings as options. For instance `ActionView::Helpers::FormHelper` defines:
@@ -2799,11 +2805,14 @@ The method `symbolize_keys` returns a hash that has a symbolized version of the
WARNING. Note in the previous example only one key was symbolized.
-The result in case of collision is undefined:
+The result in case of key collision is not guaranteed:
```ruby
{"a" => 1, a: 2}.symbolize_keys
-# => {:a=>2}, in my test, can't rely on this result though
+# The result could either be
+# => {:a=>2}
+# or
+# => {:a=>1}
```
This method may be useful for example to easily accept both symbols and strings as options. For instance `ActionController::UrlRewriter` defines