Created
September 10, 2013 07:08
-
-
Save missingno15/6505948 to your computer and use it in GitHub Desktop.
LRtHW PDF Exercise 40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# ok pay attention! | |
cities[:find] = method(:find_city) | |
while true | |
print "State? (ENTER to quit) " | |
state = gets.chomp | |
break if state.empty? | |
# this line is the most important ever! study! | |
puts cities[:find].call(cities, state) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I take it this was a lesson from something? Otherwise I don't get why lines 5 & 6 aren't declared in the initial hash.