Can include method be used for multiple values in Ruby?

I have that snippet of Ruby code.
$letters_arr is an array of letters of a random word . The user will enter a letter for example “a” which will be assigned to user_choice variable.
Then the IF statement checks if that letter is included in $letters_arr . If the letter was included once then it will be pushed to a new array with no problem and all works fine, but if the letter was included more than one time . The first time will cause no error but second time when the user enters the letter again will cause problem !

The thing i want to do is when the user enters the letter and i check if it is included . If it was included more than one time then the letter will be pushed to all locations that is included in all at once.

For example if the letter was “a” and it was included in $letters_arr[0] , $letters_arr[3] , $letters_arr[5] then the push method push it in all of those indexes.

Is there a method for that ? or how i will be able to solve that problem ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs