I have a [m X n] double-dimensional array in Ruby and I’m trying to
sort the entries (rows) by the 6-th column, which is a DateTime
object. Things get a little bit complicated, since I might have a nil
value in that column. If that happens, then I want to sort by the 7-th
This is what I have so far:
cset_arr = cset_arr.sort do |x, y|
if x.nil? && y.nil?
x <=> y
elsif x.nil? && !y.nil?
y # ???
elsif !x.nil? && y.nil?
x # ???
elsif !x.nil? && !y.nil?
x <=> y
For the second and third if statements, I don’t know how to “select”
that value. So, for example, if both 6-th columns are nil, then
compare by the 7-th column (first if). But, if the first record has a
nil 6-th column and the second record has a non-nil 6-th column, then
how do I set the second record as being the “selected” one of the two?
The current form (e.g. y) does not work.