Skip to content

Instantly share code, notes, and snippets.

@ckozus
Created February 15, 2012 19:31
Show Gist options
  • Save ckozus/1838360 to your computer and use it in GitHub Desktop.
Save ckozus/1838360 to your computer and use it in GitHub Desktop.
if RUBY_VERSION < '1.8.7'
class Array
alias original_index index
def index *args
if args.length > 0
return original_index(*args)
else
pos = nil
each_with_index do |element, i|
if yield(element)
return i
end
end
return nil
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment