Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/nutella/core_ext/object/blank.rb,
lib/nutella/core_ext/object/aliases.rb
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Returns true if the object is false, empty, or a whitespace string.
-
#presence ⇒ Object, NilClass
Returns the object if it is present, returns
nil
if the object is blank. -
#present? ⇒ Boolean
The inverse of Object#blank?.
Instance Method Details
#blank? ⇒ Boolean
Returns true if the object is false, empty, or a whitespace string.
nil.blank? # => true
false.blank? # => true
4.blank? # => false
15 16 17 |
# File 'lib/nutella/core_ext/object/blank.rb', line 15 def blank? respond_to?(:empty?) ? empty? : !self end |
#presence ⇒ Object, NilClass
Returns the object if it is present, returns nil
if the object is blank.
"str".presence # => "str"
"".presence # => nil
33 34 35 |
# File 'lib/nutella/core_ext/object/blank.rb', line 33 def presence self if present? end |
#present? ⇒ Boolean
The inverse of Object#blank?.
22 23 24 |
# File 'lib/nutella/core_ext/object/blank.rb', line 22 def present? !blank? end |