我有一些代码可以在数组(线索)中找到关键字并返回其位置,我正在尝试获取此结果并将其作为 puts 命令执行。此搜索是必要的,因为我并不总是知道“软件包含”在数组中的位置
我下面的代码只是简单的输出“线索 [2]”,但我想实际执行 puts 线索 [2],就好像我已经输入了它一样,所以我的输出将是“包含软件”。
有没有办法让这个可行?
clues = Array.new
clues << 'Power supply type'
clues << 'Slots'
clues << 'Software included'
Var100 = clues.rindex('Software included')
Var101 = "clues[#{Var100}]"
command_store = Array.new
command_store << lambda {puts "clues[#{Var101}]" }