我是编程Ruby的新手,我需要一些帮助。
我想在检查时显示客户代码和客户名称。但我只得到客户代码而不是客户名称。我如何获得客户名称?
customer = {
C00001: "Tyler Dinges",
C00002: "Jannie de Vries",
C00003: "Klaas Bruinsma",
}
when 'searchcustomer'
puts "Witch customer are you looking for?"
customernumber = gets.chomp
if customer[customernumber.to_sym].nil?
puts "customer is not found"
else
customernumber == customer[customernumber.to_sym]
customer[customernumber.to_sym]
puts "#{customernumber} #{customername} Is a customer!"
end
感谢您的帮助!
答案 0 :(得分:0)
您需要删除when
关键字。
customer = {
C00001: "Tyler Dinges",
C00002: "Jannie de Vries",
C00003: "Klaas Bruinsma",
}
puts "Witch customer are you looking for?"
customernumber = gets.chomp
if customer[customernumber.to_sym].nil?
puts "customer is not found"
else
customername = customer[customernumber.to_sym]
puts "#{customernumber} #{customername} Is a customer!"
end
我删除了customernumber == customer[customernumber.to_sym]
,因为它已由gets