find_index

ary.index(obj) â int or nil
ary.index { |item| block } â int or nil
ary.index â Enumerator
Instance Public methods

Returns the index of the first object in ary such that the object is == to obj.

If a block is given instead of an argument, returns the index of the first object for which the block returns true. Returns nil if no match is found.

See also #rindex.

An Enumerator is returned if neither a block nor argument is given.

a = [ "a", "b", "c" ]
a.index("b")              #=> 1
a.index("z")              #=> nil
a.index { |x| x == "b" }  #=> 1

This is an alias of #find_index.

doc_ruby_on_rails
2015-03-30 17:05:44
Comments
Leave a Comment

Please login to continue.