instance method
compact_blank
Ruby on Rails 8.0.4
Since v6.1.7.10Signature
compact_blank()
Returns a new Array without the blank items. Uses Object#blank? for determining if an item is blank.
[1, "", nil, 2, " ", [], {}, false, true].compact_blank # => [1, 2, true] Set.new([nil, "", 1, false]).compact_blank # => [1]
When called on a Hash, returns a new Hash without the blank values.
{ a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
# => { b: 1, f: true }
Source
# File activesupport/lib/active_support/core_ext/enumerable.rb, line 184
def compact_blank
reject(&:blank?)
end
Defined in activesupport/lib/active_support/core_ext/enumerable.rb line 184
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Enumerable