The removal methods for removing a given value from an array all seem to remove every instance of a supplied value. Without knowing its position, how could I only remove a single instance?
foo = 4,4,3,2,6
foo -= [4]
p foo # --> [3, 2, 6]
I get the same result with foo.delete(4)
I can query the array to discern if an instance of the value exists within it and count the number of instances:
foo = 4,4,3,2,6
foo.include?(4) # <-- true
foo.count(4) # <-- 2
If, for example, an array of dice rolls were made for a game of Yahtzee:
roll_1 = Array.new(5) {rand(1..6)}
and the resulting values were [4, 4, 3, 2, 6] the player might want to select either both fours, or, 2, 3, & 4 for a straight. In the case where the player wants to hold on to a single four for a straight, how can they choose this single instance of the value in a way that the value is verified as being in the array?