Skip to content

Instantly share code, notes, and snippets.

@missingno15
Created September 10, 2013 07:08
Show Gist options
  • Save missingno15/6505948 to your computer and use it in GitHub Desktop.
Save missingno15/6505948 to your computer and use it in GitHub Desktop.
LRtHW PDF Exercise 40
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
@drewbaumann
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment