Is there a rails function to detect ["", "", ...](i.e. an array containing only an empty string or strings) as empty
["", "", ...]
My requirement:
[""].foo? => true
[""].foo?
["", ""].foo? => true
["", ""].foo?
["lorem"].foo? => false
["lorem"].foo?
["", "ipsum"].foo? => false
["", "ipsum"].foo?
I tried to use array.reject!(&:empty?).blank?. It worked, but it changed my array. I do not want my array to be modified. Please help me find a compact method.
array.reject!(&:empty?).blank?
There is no single method, but you can use , .all?
.all?
["", nil].all?(&:blank?) # => true ["ipsum", ""].all?(&:blank?) # => false
Or you can get the opposite result with , .any?
.any?
["", nil].any?(&:present?) # => false ["lorem", ""].any?(&:present?) # => true
OP Rails, , Ruby. present? present? blank? Rails ( ActiveSupport, ).
present?
blank?
:
[nil, nil].join.empty? # => true ["", nil].join.empty? # => true ["lorem", nil].join.empty? # => false