diff options
author | claudiob <claudiob@gmail.com> | 2014-12-20 10:01:58 -0800 |
---|---|---|
committer | claudiob <claudiob@gmail.com> | 2014-12-22 03:44:20 +0100 |
commit | 0222cefc405c4de7e4667a20c8e3cc4fd3200497 (patch) | |
tree | 728c5659f8d39e88f0860d561167b604820136a2 /activesupport | |
parent | 15590c1a2a76b6560840cfa55c5a2485b4566460 (diff) | |
download | rails-0222cefc405c4de7e4667a20c8e3cc4fd3200497.tar.gz rails-0222cefc405c4de7e4667a20c8e3cc4fd3200497.tar.bz2 rails-0222cefc405c4de7e4667a20c8e3cc4fd3200497.zip |
Add docs for `Object.nil!`
Also add doc examples for `Object.nil`.
[ci skip]
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/try.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index 26b8d58948..6b3fc48a3f 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -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 |