I have an array with unique elements. Is there a way to replace a specific value in it with another value without using its index value?
Examples:
array = [1,2,3,4] if array.include? 4 # "replace 4 with 'Z'" end array #=> [1,2,3,'Z'] hash = {"One" => [1,2,3,4]} if hash["One"].include? 4 # "replace 4 with 'Z'" end hash #=> {"One" => [1,2,3,'Z']}
source share