【发布时间】:2014-12-21 10:07:40
【问题描述】:
有没有办法从数组中获取索引值?
class Datadump
def ddlist()
@tobethrown = [
sofa = ["red", "blue", "striped"],
toys = ["figures", "robots", "comics"]
]
end
def dddig(chkdump)
#check index value of array from string
#I expect [1][2]
end
end
dumpoop = Datadump.new
dumpoop.ddlist()
dumpoop.dddig("comics")
如果内容只是 ["sofa", "toys"] 而不是它们作为变量,我可以使用 tobethrown.index() 获取值。我是 ruby 新手,如果这是一个菜鸟问题,请原谅我。
【问题讨论】:
标签: ruby arrays class indexing