Method: Hash#compact_blank!
- Defined in:
- activesupport/lib/active_support/core_ext/enumerable.rb
#compact_blank! ⇒ Object
Removes all blank values from the Hash
in place and returns self. Uses Object#blank? for determining if a value is blank.
h = { a: "", b: 1, c: nil, d: [], e: false, f: true }
h.compact_blank!
# => { b: 1, f: true }
232 233 234 235 |
# File 'activesupport/lib/active_support/core_ext/enumerable.rb', line 232 def compact_blank! # use delete_if rather than reject! because it always returns self even if nothing changed delete_if { |_k, v| v.blank? } end |