Sha256: 2a58e3279876ba018c1ab0e51b866be0f00ff1f7bee5c6ca184031f92ddb9e64

Contents?: true

Size: 436 Bytes

Versions: 41

Compression:

Stored size: 436 Bytes

Contents

# frozen_string_literal: true

class Pathname
  # Returns the receiver if the named file exists otherwise returns +nil+.
  # <tt>pathname.existence</tt> is equivalent to
  #
  #    pathname.exist? ? pathname : nil
  #
  # For example, something like
  #
  #   content = pathname.read if pathname.exist?
  #
  # becomes
  #
  #   content = pathname.existence&.read
  #
  # @return [Pathname]
  def existence
    self if exist?
  end
end

Version data entries

41 entries across 38 versions & 8 rubygems

Version Path
activesupport-7.0.0 lib/active_support/core_ext/pathname/existence.rb