mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add docs for Object.nil!
Also add doc examples for `Object.nil`. [ci skip]
This commit is contained in:
parent
15590c1a2a
commit
0222cefc40
1 changed files with 9 additions and 3 deletions
|
@ -63,9 +63,12 @@ class Object
|
|||
try!(*a, &b) if a.empty? || respond_to?(a.first)
|
||||
end
|
||||
|
||||
# Same as #try, but will raise a NoMethodError exception if the receiver is not +nil+ and
|
||||
# does not implement the tried method.
|
||||
|
||||
# Same as #try, but will raise a NoMethodError exception if the receiver is
|
||||
# not +nil+ and does not implement the tried method.
|
||||
#
|
||||
# "a".try!(:upcase) # => "A"
|
||||
# nil.try!(:upcase) # => nil
|
||||
# 123.try!(:upcase) # => NoMethodError: undefined method `upcase' for 123:Fixnum
|
||||
def try!(*a, &b)
|
||||
if a.empty? && block_given?
|
||||
if b.arity.zero?
|
||||
|
@ -94,6 +97,9 @@ class NilClass
|
|||
nil
|
||||
end
|
||||
|
||||
# Calling +try!+ on +nil+ always returns +nil+.
|
||||
#
|
||||
# nil.try!(:name) # => nil
|
||||
def try!(*args)
|
||||
nil
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue