instance method existence

Ruby on Rails 8.1.2

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

existence()

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]

Source
# File activesupport/lib/active_support/core_ext/pathname/existence.rb, line 20
  def existence
    self if exist?
  end

Defined in activesupport/lib/active_support/core_ext/pathname/existence.rb line 20 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Pathname

Type at least 2 characters to search.

↑↓ navigate · open · esc close