mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
rails guide for Pathname#existence
This commit is contained in:
parent
1a14bcb8cd
commit
a2e9e33dae
1 changed files with 15 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue