我正在尝试创建一个已注册事件的成员数组,而不是创建一个包含多个散列的数组,代码只存储要注册到散列中的最后一个成员。我似乎无法弄清楚为什么。
total = 0
def registration
members = []
event = {}
puts "First Name: "; members << gets.chomp
puts "Last Name: "; members << gets.chomp
puts "Date of Birth: "; members << gets.chomp
puts "Number of Events(1-4): "; members << gets.chomp.to_i
total = '%.2f' % [(members[3] * 35.00)]
puts "TOTAL DUE: $#{total}"
event = {
:first_name => members[0],
:last_name => members[1],
:dob => members[2],
:events => members[3],
:paid => total
}
puts "Would you like to register another student?"
answer = gets.chomp.downcase
if answer == "yes"
registration
elsif answer == "no"
puts "Thank you for registering. We look forward to seeing you at the event."
p event
else
puts "Please enter 'yes' or 'no'."
end
end
registration