From a2e9e33dae9ffc16de2a541a39d47c61d60db73f Mon Sep 17 00:00:00 2001 From: Timo Schilling Date: Thu, 25 Nov 2021 20:18:03 +0000 Subject: [PATCH] rails guide for Pathname#existence --- guides/source/active_support_core_extensions.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 8617429d96..9f663226cc 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -4055,3 +4055,18 @@ end NOTE: Defined in `active_support/core_ext/load_error.rb`. [LoadError#is_missing?]: https://api.rubyonrails.org/classes/LoadError.html#method-i-is_missing-3F + +Extensions to Pathname +------------------------- + +### `existence` + +The [`existence`][Pathname#existence] method returns the receiver if the named file exists otherwise returns +nil+. It is useful for idioms like this: + +```ruby +content = Pathname.new("file").existence&.read +``` + +NOTE: Defined in `active_support/core_ext/pathname/existence.rb`. + +[Pathname#existence]: https://api.rubyonrails.org/classes/Pathname.html#method-i-existence