Difference between index and find_index

Is there a difference between Array#index and Array#find_index? I can’t
see one from reading the docs, but the docs also do NOT say that one
method is just an alias to the other one, so there should be a
difference.

Ronald

The docs aren’t perfect.

When we take alook a the ruby C-source, the comments above the function
rb_ary_index strongly suggest that #index and #find_index are the same.

https://github.com/ruby/ruby/blob/4df168074c9e80822b4326a4539600ae7dbe0adb/array.c

To confirm this, we ask ruby itself:

a = Array.instance_method :index
b = Array.instance_method :find_index
c = Array.instance_method :rindex
puts a.eql? b # => true
puts a.eql? c # => false

See UnboundMethod#eql?

http://ruby-doc.org/core-2.2.0/UnboundMethod.html#method-i-eql-3F

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs