Refactoring :ancestors_equal? method