提交 0222cefc 编写于 作者: C claudiob

Add docs for `Object.nil!`

Also add doc examples for `Object.nil`.

[ci skip]
上级 15590c1a
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册