我希望这种方法可以遍历名称数组中的每个项目katz_deli
并用于puts
显示名称及其索引。但是,输出只是数组中的第一个名称及其索引。
我的代码:
def line (katz_deli)
if katz_deli.count > 1
katz_deli.each_with_index {|name, index| puts "The line is currently: #{index +1}. #{name}" }
else
puts "The line is currently empty."
end
end
我希望我的输出是"The line is currently: 1. Logan 2. Avi 3. Spencer"
但我得到了"The line is currently: 1. Logan."
谢谢!