instance method
compact_blank
Ruby on Rails 6.1.7.10
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, 2]) # => [2, 1] (or [1, 2])
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 191
def compact_blank
reject(&:blank?)
end
Defined in activesupport/lib/active_support/core_ext/enumerable.rb line 191
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Enumerable