On this page
class Pathname
Public Instance Methods
# File activesupport/lib/active_support/core_ext/pathname/existence.rb, line 18
def existence
self if exist?
end
Returns the receiver if the named file exists otherwise returns nil
. pathname.existence
is equivalent to
pathname.exist? ? pathname : nil
For example, something like
content = pathname.read if pathname.exist?
becomes
content = pathname.existence&.read
@return [Pathname]
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.