Class: Pathname
- Defined in:
- lib/active_support/core_ext/object/json.rb,
lib/active_support/core_ext/pathname/blank.rb,
lib/active_support/core_ext/pathname/existence.rb
Overview
:nodoc:
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
-
#blank? ⇒ true, false
An Pathname is blank if it’s empty:.
-
#existence ⇒ Pathname
Returns the receiver if the named file exists otherwise returns
nil
. -
#present? ⇒ Boolean
:nodoc:.
Instance Method Details
#as_json(options = nil) ⇒ Object
237 238 239 |
# File 'lib/active_support/core_ext/object/json.rb', line 237 def as_json( = nil) to_s end |
#blank? ⇒ true, false
13 14 15 |
# File 'lib/active_support/core_ext/pathname/blank.rb', line 13 def blank? to_s.empty? end |
#existence ⇒ Pathname
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
20 21 22 |
# File 'lib/active_support/core_ext/pathname/existence.rb', line 20 def existence self if exist? end |
#present? ⇒ Boolean
:nodoc:
17 18 19 |
# File 'lib/active_support/core_ext/pathname/blank.rb', line 17 def present? # :nodoc: !to_s.empty? end |