-
-
Save corey/132031 to your computer and use it in GitHub Desktop.
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
module Enumerable | |
def return | |
each do |i| | |
value = yield(i) | |
return value if value | |
end | |
nil | |
end | |
end | |
h = {0 => 'a', 2 => 'b'} | |
[1,2,3].return {|x| h[x]} # => b | |
[4,5,6].return {|x| h[x]} # => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment