Using magical -1 is a mistake from imperative programming, because tomorrow those incoming numbersYou can happen to be negative. Correct solution is to create temporary sorting columns:
def sort records, *attrs
records.sort_by do |h|
h.values_at(*attrs).map do |v|
v.nil? ? [2] : [1, v]
end
end
end
Here I added columns with values 1 or 2 to the left for higher priority -- could add to the right or even in between for more complex sorting.