【发布时间】:2019-06-03 03:19:00
【问题描述】:
我要求用户输入键 currentline 和值 currentstation,以便将其与哈希进行比较,并显示要走哪条线。
mtahash = {
n: ["timesq", "34thn", "28thn", "23rdn", "Union_Square", "8th"],
l: ["8th", "6th", "Union_Square", "3rd", "1st"],
s: ["Grand Central", "33rds", "28th", "23rds", "Union Square", "Astor Place"]
}
puts "Please enter your current station"
current_station = gets.chomp
puts "Please enter your current line"
current_line = gets.chomp
mtahash.each do |key, value|
if key == current_line && value == current_station
puts "got it"
else
puts "fish"
end
end
无论输入如何,我的代码都会输出fish 三次。
【问题讨论】:
-
它是一个字符串,应该是哈希中的任何值
-
我对学习编码和 ruby 非常陌生——要学习的东西太多了,但我正在学习,我最终会到达那里。 :)