instance method compact_blank!

Ruby on Rails 7.1.6

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

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 227
  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 227 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Hash

Type at least 2 characters to search.

↑↓ navigate · open · esc close