Class: Pathname
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activesupport/lib/active_support/core_ext/pathname/blank.rb, activesupport/lib/active_support/core_ext/object/json.rb, activesupport/lib/active_support/core_ext/pathname/existence.rb |
Instance Attribute Summary
-
#blank? ⇒ true, false
readonly
An Pathname is blank if it’s empty:
- #present? ⇒ Boolean readonly Internal use only
Instance Method Summary
-
#existence ⇒ Pathname
Returns the receiver if the named file exists otherwise returns
nil
. - #as_json(options = nil) Internal use only
Instance Attribute Details
#blank? ⇒ true
, false
(readonly)
An Pathname is blank if it’s empty:
Pathname.new("").blank? # => true
Pathname.new(" ").blank? # => false
Pathname.new("test").blank? # => false
# File 'activesupport/lib/active_support/core_ext/pathname/blank.rb', line 13
def blank? to_s.empty? end
#present? ⇒ Boolean
(readonly)
This method is for internal use only.
[ GitHub ]
# File 'activesupport/lib/active_support/core_ext/pathname/blank.rb', line 17
def present? # :nodoc: !to_s.empty? end
Instance Method Details
#as_json(options = nil)
This method is for internal use only.
[ GitHub ]
# File 'activesupport/lib/active_support/core_ext/object/json.rb', line 237
def as_json( = nil) to_s 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
# File 'activesupport/lib/active_support/core_ext/pathname/existence.rb', line 20
def existence self if exist? end