Let's say I have an array of: [{one: 1, two: 2}, {one: 5, two: 6}]
and I want to use sort_by something like:
[1] pry(main)> [{one: 1, two: 2}, {one: 5, two: 6}].sort_by{|x| [x[:one], x[:two]]}
However when I introduce nil for one of the values I get ArgumentError: comparison of Array with Array failed
:
=> [{:one=>1, :two=>2}, {:one=>5, :two=>6}]
[2] pry(main)> [{one: 1, two: 2}, {one: nil, two: 6}].sort_by{|x| [x[:one], x[:two]]}
ArgumentError: comparison of Array with Array failed
How can I avoid this error?