爲什麼我不能做到以下幾點:紅寶石:訪問數組
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