Mastermind edge case defeats given specs

I found an edge case when playing the game once I passed all the specs.
The problem code passes the specs except for an edge case for example secret = “yygg” with a guess of “yyyy” would return -1 with my problem code. but it still passes the specs.

problem code:
def near_matches(guess)
near_count = guess.pegs.uniq.reduce(0) {|count, peg| pegs.include?(peg) ? count+1 : count }
near_count - exact_matches(guess)
end

working:
def near_matches(guess)
not_matched_guesses = []
not_matched_secrets = []
(0…3).each do |idx|
unless pegs[idx] == guess.pegs[idx]
not_matched_guesses << guess.pegs[idx]
not_matched_secrets << pegs[idx]
end
end
near_count = not_matched_guesses.uniq.reduce(0) {|count, peg| not_matched_secrets.include?(peg) ? count+1 : count }
end