As we know compact in Array, it works like this :
[ "a", nil, "b", nil, "c", nil ].compact
#=> [ "a", "b", "c" ]
Is there a function similar to do that for an array two dimentions ?
[[nil, nil], ["Prestation Standard", 1]].compact => [["Prestation Standard", 1]]
This would work:
ary = [[nil, nil], ["Prestation Standard", 1]]
ary.map(&:compact).reject(&:empty?)
#=> [["Prestation Standard", 1]]
map(&:compact) returns a new 2D array with all nil values removed from the inner arrays and reject(&:empty?) removes those that are empty.