我已經有一個學校的哈希圖,它具有作爲學生的名字的關鍵。我想提取所有信息並創建散列圖,並將學生的School_ID
作爲主鍵。 我收到錯誤如何從紅寶石散列圖中提取值並存儲在數組中?
未定義局部變量或者用於主要方法「KEY1」:對象
key1 = Array.new
array2 = Array.new
def print_info(school_hash)
school_hash.each do |student| #school_hash has key as first name
#student[0] contains First Name student[1] all info
key1.push(student[1].School_ID) #save school_id separately to use as a key
array2.push(student[1]) # all infos including Address, Grade, School_ID, Sports
end
new_hash = Hash[key1.zip(array2)]
printf("%s",new_hash)
end