为什么我不能做到以下几点:红宝石:访问数组
current_location = 'omaha'
omaha = []
omaha[0] = rand(10)
omaha[1] = rand(10) + 25
omaha[2] = rand(5) + 10
puts "You are currently in #{current_location}."
puts "Fish is worth #{omaha[0]}"
puts "Coal is worth #{current_location[1]}"
puts "Cattle is worth #{current_location[2]}"
奥马哈[0]行工作,但CURRENT_LOCATION [1]没有。我怀疑这是因为omaha是一个字符串,而我的puts是为该字母返回一个ASCII码(这实际上是发生了什么)。
我该如何解决这个问题?
你期望什么? – fl00r
我需要能够采取我的current_location和访问基于该值的数组。 –
'current_location [1]'应该返回'omaha [1]'??? – fl00r