Skip to content

Commit a2e9e33

Browse files
rails guide for Pathname#existence
1 parent 1a14bcb commit a2e9e33

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

guides/source/active_support_core_extensions.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,3 +4055,18 @@ end
40554055
NOTE: Defined in `active_support/core_ext/load_error.rb`.
40564056

40574057
[LoadError#is_missing?]: https://api.rubyonrails.org/classes/LoadError.html#method-i-is_missing-3F
4058+
4059+
Extensions to Pathname
4060+
-------------------------
4061+
4062+
### `existence`
4063+
4064+
The [`existence`][Pathname#existence] method returns the receiver if the named file exists otherwise returns +nil+. It is useful for idioms like this:
4065+
4066+
```ruby
4067+
content = Pathname.new("file").existence&.read
4068+
```
4069+
4070+
NOTE: Defined in `active_support/core_ext/pathname/existence.rb`.
4071+
4072+
[Pathname#existence]: https://api.rubyonrails.org/classes/Pathname.html#method-i-existence

0 commit comments

Comments
 (0)