Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Created November 24, 2011 14:06
Show Gist options
  • Save balinterdi/1391427 to your computer and use it in GitHub Desktop.
Save balinterdi/1391427 to your computer and use it in GitHub Desktop.
module Enumerable
def find_value(&block)
found = nil
self.each do |e|
found = block.call(e)
return found if found
end
found
end
end
def profession(man)
{ 'einstein' => 'scientist', 'edison' => 'inventor', 'nietzsche' => 'philosopher' }[man]
end
def find_famous_profession(famous_people)
famous_people.find_value { |famous| profession(famous) }
end
p find_famous_profession(['hume', 'turing', 'yeats', 'nietzsche'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment