instance method
compact_blank!
Ruby on Rails 7.0.10
Since v6.1.7.10Signature
compact_blank!()
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 }
Source
# File activesupport/lib/active_support/core_ext/enumerable.rb, line 283
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
Defined in activesupport/lib/active_support/core_ext/enumerable.rb line 283
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Hash