-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39.rb
More file actions
44 lines (37 loc) · 1.02 KB
/
39.rb
File metadata and controls
44 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# create a mapping of state to abbreviation
states = {
'Oregon' => 'OR',
'Florida' => 'FL',
'California' => 'CA',
'New York' => 'NY',
'Michigan' => 'MI'
}
# create a basic set of states and some cities in them
cities = {
'CA' => 'San Francisco',
'MI' => 'Detroit',
'FL' => 'Jacksonville'
}
#add cities
cities['IT'] = "Bologna"
cities['DE'] = "Berlin"
puts ' --- '
puts "CA State has: #{cities['CA']}"
puts "DE State has: #{cities['DE']}"
# puts some states
puts '-' * 10
puts "Michigan's abbreviation is: #{states['Michigan']}"
puts "Florida's abbreviation is: #{states['Florida']}"
# do it by using the state then cities dict
puts '-' * 10
puts "Michigan has: #{cities[states['Michigan']]}"
puts "Florida has: #{cities[states['Florida']]}"
#list all
puts "\n ---\n"
states.each do |s_key, s_val|
puts "key is #{s_key}, value is #{s_val}"
end
# default values using ||= with the nil result
city = cities['TX']
city ||= 'Does Not Exist'
puts "The city for the state 'TX' is: #{city}"