diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2015-11-04 18:55:18 -0200 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2015-11-04 18:55:18 -0200 |
commit | 110e49179c8ceb9d4abd6110feec1496a3eac1f0 (patch) | |
tree | f11fb141cb2889153c7cef7fcba890f9523cb782 /guides/source | |
parent | e8b2c0535c203119e6733a982dc22734f3da1219 (diff) | |
parent | 04bf3a174ed6a02b803ec91a6bd2be8f44137fd2 (diff) | |
download | rails-110e49179c8ceb9d4abd6110feec1496a3eac1f0.tar.gz rails-110e49179c8ceb9d4abd6110feec1496a3eac1f0.tar.bz2 rails-110e49179c8ceb9d4abd6110feec1496a3eac1f0.zip |
Merge pull request #22182 from seanlinsley/patch-1
document `try!` in ActiveSupport core ext guide
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 556b5ede3c..f6fc255c24 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -248,6 +248,13 @@ end @person.try { |p| "#{p.first_name} #{p.last_name}" } ``` +Note that `try` will swallow no-method errors, returning nil instead. If you want to protect against typos, use `try!` instead: + +```ruby +@number.try(:nest) # => nil +@number.try!(:nest) # NoMethodError: undefined method `nest' for 1:Fixnum +``` + NOTE: Defined in `active_support/core_ext/object/try.rb`. ### `class_eval(*args, &block)` |