You can simplify this by checking for equality:

ongoing_tasks.sort! { |a,b| (a.priority == b.priority) ? (a.creation_date <=> b.creation_date) : (b.priority <=> a.priority) }