aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_support_core_extensions.md
diff options
context:
space:
mode:
authorSean Linsley <xovatdev@gmail.com>2015-11-04 13:27:48 -0600
committerSean Linsley <xovatdev@gmail.com>2015-11-04 13:27:48 -0600
commit04bf3a174ed6a02b803ec91a6bd2be8f44137fd2 (patch)
treef11fb141cb2889153c7cef7fcba890f9523cb782 /guides/source/active_support_core_extensions.md
parente8b2c0535c203119e6733a982dc22734f3da1219 (diff)
downloadrails-04bf3a174ed6a02b803ec91a6bd2be8f44137fd2.tar.gz
rails-04bf3a174ed6a02b803ec91a6bd2be8f44137fd2.tar.bz2
rails-04bf3a174ed6a02b803ec91a6bd2be8f44137fd2.zip
document `try!` in ActiveSupport core ext guide
https://twitter.com/avdi/status/660141673993777156
Diffstat (limited to 'guides/source/active_support_core_extensions.md')
-rw-r--r--guides/source/active_support_core_extensions.md7
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)`