Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/if_blank.rb
Instance Method Summary collapse
-
#if_blank?(replacement = "") ⇒ Boolean
Check to see if the current string is empty (empty).
Instance Method Details
#if_blank?(replacement = "") ⇒ Boolean
Check to see if the current string is empty (empty). If it is, allow its return value to be the result of a passed in block, or else a replacement string Converts self to a string.
10 11 12 13 14 15 16 |
# File 'lib/if_blank.rb', line 10 def if_blank?(replacement = "") return self unless self.tap do |obj| obj.strip! if obj.respond_to?(:strip!) end.empty? block_given? ? yield : replacement end |