我需要将一个变量添加到Hash中。我试图这样做:
actorsChickens = Hash.new
nicolasCage = gets.chomp # is a string
chickenCount = gets.chomp # is a string representing a number (i.e "5")
actorsChickens[#{nicolasCage} => #{chickenCount}]
我做错了什么?如何将变量添加到哈希?
答案 0 :(得分:4)
我认为你正在尝试这样做:
your_hash = {}
hash_key = gets.chomp
hash_value = gets.chomp
your_hash[hash_key] = hash_value