diff options
author | yui-knk <spiketeika@gmail.com> | 2015-04-17 23:30:50 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2015-04-19 23:22:49 +0900 |
commit | c94577dd5c349a53e85eca1913cfbf1efe0e7eb9 (patch) | |
tree | 8c89087d434c11f290287900a3878531611dd2eb | |
parent | f7a61c202659533e717f0832c40b79817e1a79de (diff) | |
download | rails-c94577dd5c349a53e85eca1913cfbf1efe0e7eb9.tar.gz rails-c94577dd5c349a53e85eca1913cfbf1efe0e7eb9.tar.bz2 rails-c94577dd5c349a53e85eca1913cfbf1efe0e7eb9.zip |
[ci skip] Fix docs and guide about 'Array.wrap'
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/wrap.rb | 7 | ||||
-rw-r--r-- | guides/source/active_support_core_extensions.md | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb index 152eb02218..d29b0a4f9b 100644 --- a/activesupport/lib/active_support/core_ext/array/wrap.rb +++ b/activesupport/lib/active_support/core_ext/array/wrap.rb @@ -15,12 +15,13 @@ class Array # # * 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>Array.wrap</tt> returns - # +nil+ right away. + # an array with the argument as its single element 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, but returns an empty array if argument is +nil+. + # * It does not call +to_a+ on the argument, if the argument does not respond to +to_ary+ + # it returns an array with the argument as its single element. # - # The second point is easily explained with some enumerables: + # The last point is easily explained with some enumerables: # # Array(foo: :bar) # => [[:foo, :bar]] # Array.wrap(foo: :bar) # => [{:foo=>:bar}] diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 2967ce8355..7a9624a4ee 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2440,9 +2440,9 @@ Array.wrap(0) # => [0] This method is similar in purpose to `Kernel#Array`, but there are some differences: -* If the argument responds to `to_ary` the method is invoked. `Kernel#Array` moves on to try `to_a` if the returned value is `nil`, but `Array.wrap` returns `nil` right away. +* If the argument responds to `to_ary` the method is invoked. `Kernel#Array` moves on to try `to_a` if the returned value is `nil`, but `Array.wrap` returns an array with the argument as its single element right away. * If the returned value from `to_ary` is neither `nil` nor an `Array` object, `Kernel#Array` raises an exception, while `Array.wrap` 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. +* It does not call `to_a` on the argument, if the argument does not respond to +to_ary+ it returns an array with the argument as its single element. The last point is particularly worth comparing for some enumerables: |