我收到以下错误:获得一个“类型错误”当遍历,一个Ruby阵列
Can't convert String into Integer (TypeError)
它是在这条线发生的事情:
if new_animal != animals[i]
这究竟是为什么?
animals = ['rhino', 'giraffe', 'cat', 'dolphin', 'turtle']
puts 'Enter the new animal:'
new_animal = gets.chomp
empty_array = []
animals.each do |i|
if new_animal != animals[i]
empty_array << i
end
end