Created
April 8, 2009 04:45
-
-
Save nikz/91640 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
class Array | |
def detect_index(&block) | |
each_with_index do |e, i| | |
return i if yield e | |
end | |
end | |
end | |
>> ["a", "b", "c"].detect_index { |e| e == "c" } | |
=> 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment