Instead of .select{}.last, use .reverse_each.detect{}