класс Pathname
Публичные методы экземпляра
# File activesupport/lib/active_support/core_ext/pathname/existence.rb, line 18 def existence self if exist? end
Возвращает получатель, если указанный файл существует, в противном случае возвращает nil. pathname.existence эквивалентно
pathname.exist? ? pathname : nil
Например, что-то вроде
content = pathname.read if pathname.exist?
становится
content = pathname.existence&.read
@return [Pathname]
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.