rindex

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

Returns the index of the last object in self == to obj.

If a block is given instead of an argument, returns the index of the first object for which the block returns true, starting from the last object.

Returns nil if no match is found.

See also #index.

If neither block nor argument is given, an Enumerator is returned instead.

a = [ "a", "b", "b", "b", "c" ]
a.rindex("b")             #=> 3
a.rindex("z")             #=> nil
a.rindex { |x| x == "b" } #=> 3
doc_ruby_on_rails
2015-03-30 19:26:12
Comments
Leave a Comment

Please login to continue.