Clarify try calls public methods only

This commit is contained in:
Lewis Buckley 2021-10-01 13:50:07 +01:00
parent 2ed58965fd
commit 0f1cdec9d7
No known key found for this signature in database
GPG Key ID: 4A9328D3A51196CB
1 changed files with 1 additions and 1 deletions

View File

@ -220,7 +220,7 @@ NOTE: Defined in `active_support/core_ext/object/deep_dup.rb`.
### `try`
When you want to call a method on an object only if it is not `nil`, the simplest way to achieve it is with conditional statements, adding unnecessary clutter. The alternative is to use [`try`][Object#try]. `try` is like `Object#send` except that it returns `nil` if sent to `nil`.
When you want to call a method on an object only if it is not `nil`, the simplest way to achieve it is with conditional statements, adding unnecessary clutter. The alternative is to use [`try`][Object#try]. `try` is like `Object#public_send` except that it returns `nil` if sent to `nil`.
Here is an example: