Sort array of hashes with nil values last
You can 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.