我已经有一个学校的哈希图,其中键是学生的名字。我想提取所有信息并以学生School_ID
作为主键创建哈希映射。我收到错误
main:object 的未定义局部变量或方法“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