Skip to content

Instantly share code, notes, and snippets.

@mjhea0
Forked from nastysloper/hash_ex.rb
Last active December 16, 2015 22:59
Show Gist options
  • Select an option

  • Save mjhea0/5511087 to your computer and use it in GitHub Desktop.

Select an option

Save mjhea0/5511087 to your computer and use it in GitHub Desktop.
learn ruby the hard way
cities = {'CA' => 'San Francisco', 'MI' => 'Detroit', 'FL' => 'Jacksonville'}
cities['NY'] = 'New York'
cities['OR'] = 'Portland'
def find_city(map, state)
if map.include? state
return map[state]
else
return "Not found."
end
end
while true
print "State? (Enter to quit) "
state = gets.chomp
break if state.empty?
puts find_city(cities, state)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment