我正在做我的第一个程序,一个简单的待办事项列表。我想让它让我输入一个数字,然后从列表中删除相应的项目。
不过,每次我都得到“没有从零到整数的隐式转换”。我似乎无法解决它。有任何想法吗?
$list = Array.new
def mainmethod
puts "Enter new item, or type 'view' to view the list, 'delete' to delete items"
input = gets.chomp
if input.downcase == "view"
puts "Your to do list is as follows:"
puts $list
elsif input.downcase == "delete"
puts "Which item would you like to delete? (Enter a number)"
deletenumber = gets.chomp.to_i
deletenumber-=1
delete_list = [deletenumber]
delete_list.each do |del|
$list.delete_at($list.index(del))
end
else
$list << input
puts "Added to list!"
end
end
loop { mainmethod }