I'm a beginner at programming, and I'm trying to complete Zed Shaw's book for Ruby, and I just cannot understand the last for
statement of the code. If the variables state
and abbrev
have not been defined, how does the software know where to get values for them?
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