mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
documentation fixes for Array.wrap and AR::Validations::AssociatedValidator
This commit is contained in:
parent
5ea8ff0951
commit
14254d82a9
2 changed files with 8 additions and 8 deletions
|
@ -9,8 +9,8 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
module ClassMethods
|
||||
# Validates whether the associated object or objects are all valid
|
||||
# themselves. Works with any kind of association.
|
||||
# Validates whether the associated object or objects are all valid.
|
||||
# Works with any kind of association.
|
||||
#
|
||||
# class Book < ActiveRecord::Base
|
||||
# has_many :pages
|
||||
|
|
|
@ -15,12 +15,12 @@ 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
|
||||
# such a +nil+ right away.
|
||||
# +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.
|
||||
# * It does not call +to_a+ on the argument, but returns an empty array if argument is +nil+.
|
||||
#
|
||||
# The last point is particularly worth comparing for some enumerables:
|
||||
# The second point is easily explained with some enumerables:
|
||||
#
|
||||
# Array(foo: :bar) # => [[:foo, :bar]]
|
||||
# Array.wrap(foo: :bar) # => [{:foo=>:bar}]
|
||||
|
@ -29,10 +29,10 @@ class Array
|
|||
#
|
||||
# [*object]
|
||||
#
|
||||
# which for +nil+ returns <tt>[]</tt>, and calls to <tt>Array(object)</tt> otherwise.
|
||||
# which returns <tt>[]</tt> for +nil+, but calls to <tt>Array(object)</tt> otherwise.
|
||||
#
|
||||
# Thus, in this case the behavior may be different for +nil+, and the differences with
|
||||
# <tt>Kernel#Array</tt> explained above apply to the rest of <tt>object</tt>s.
|
||||
# The differences with <tt>Kernel#Array</tt> explained above
|
||||
# apply to the rest of <tt>object</tt>s.
|
||||
def self.wrap(object)
|
||||
if object.nil?
|
||||
[]
|
||||
|
|
Loading…
Reference in a new issue