Skip to content

Instantly share code, notes, and snippets.

@nikz
Created April 8, 2009 04:45
Show Gist options
  • Save nikz/91640 to your computer and use it in GitHub Desktop.
Save nikz/91640 to your computer and use it in GitHub Desktop.
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