In the following piece of code, due_date and position are optional fields, whereas important is a field which is always set to either true or false.
posts.sort_by do |post|
[post.due_date || 0, post.position || 0, post.important? ? 0 : 1]
end
I'm trying to figure out how multiple sort works. If due_date is present, then it takes precedence or sets it to zero. Why are we something setting it to zero here?
!=, e.g., if thedue_dateisn't equal, that's the comparison. If it is, it'sposition, etc. You set something to zero as a way of providing a default value if there's nothing in that field.