Method: Array#compact_blank!
- Defined in:
- activesupport/lib/active_support/core_ext/enumerable.rb
#compact_blank! ⇒ Object
Removes all blank elements from the Array in place and returns self. Uses Object#blank? for determining if an item is blank.
a = [1, "", nil, 2, " ", [], {}, false, true]
a.compact_blank!
# => [1, 2, true]
263 264 265 266 |
# File 'activesupport/lib/active_support/core_ext/enumerable.rb', line 263 def compact_blank! # use delete_if rather than reject! because it always returns self even if nothing changed delete_if(&:blank?) end |