aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-07-28 03:49:04 +0200
committerXavier Noria <fxn@hashref.com>2010-07-28 03:49:04 +0200
commite17e08efef68e9865cfbd5c0155b3d9734339192 (patch)
tree89cb96a7d2c6a3c152af9fdbbd1b58e1334eaa28 /railties/guides/source/active_support_core_extensions.textile
parent5d3e8ee2bdd2225fe6e610c7e465bb69234871ed (diff)
downloadrails-e17e08efef68e9865cfbd5c0155b3d9734339192.tar.gz
rails-e17e08efef68e9865cfbd5c0155b3d9734339192.tar.bz2
rails-e17e08efef68e9865cfbd5c0155b3d9734339192.zip
adds test coverage for edge-cases of Array.wrap, and better documentation for how it differs from Kernel#Array
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile9
1 files changed, 8 insertions, 1 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index d14a531abe..fc59df9fe4 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -2229,7 +2229,14 @@ NOTE: Defined in +active_support/core_ext/array/conversions.rb+.
h4. Wrapping
-The class method +Array.wrap+ behaves like the function +Array()+ except that it does not try to call +to_a+ on its argument. That changes the behavior for enumerables:
+The class method +Array.wrap+ behaves like the function +Array()+ except:
+
+* If the argument responds to +to_ary+ the method is invoked. <tt>Kernel#Array</tt> moves on to try +to_a+ if the returned value is +nil+, but <tt>Arraw.wrap</tt> returns such a +nil+ right away.
+* If the returned value from +to_ary+ is neither +nil+ nor an +Array+ object, <tt>Kernel#Array</tt> raises an exception, while <tt>Array.wrap</tt> does not, it just returns the value.
+* It does not call +to_a+ on the argument, though special-cases +nil+ to return an empty array.
+
+
+ that it does not try to call +to_a+ on its argument. That changes the behavior for enumerables:
<ruby>
Array.wrap(:foo => :bar) # => [{:foo => :bar}]