我是编程初学者,我正在尝试完成 Zed Shaw 的 Ruby 书籍,但我无法理解for
代码的最后一条语句。如果变量state
和abbrev
尚未定义,软件如何知道从哪里获取它们的值?
states = {
'Oregon' => 'OR',
'Florida' => 'FL',
'California' => 'CA',
'New York' => 'NY',
'Michigan' => 'MI'
}
cities = {
'CA' => 'San Francisco',
'MI' => 'Detroit',
'FL' => 'Jacksonville'
}
for state, abbrev in states
puts "%s state is abbreviated %s and has city %s" % [
state, abbrev, cities[abbrev]]
end