Add docs for Object.nil!
Also add doc examples for `Object.nil`. [ci skip]
This commit is contained in:
parent
15590c1a2a
commit
0222cefc40
@ -63,9 +63,12 @@ def try(*a, &b)
|
||||
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 @@ def try(*args)
|
||||
nil
|
||||
end
|
||||
|
||||
# Calling +try!+ on +nil+ always returns +nil+.
|
||||
#
|
||||
# nil.try!(:name) # => nil
|
||||
def try!(*args)
|
||||
nil
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user