Created
November 24, 2011 14:06
-
-
Save balinterdi/1391427 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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