Array.index with block not working

Documentation from here:
http://www.ruby-doc.org/core/classes/Array.html#M000290


Returns the index of the first object in self such that is == to obj. If
a block is given instead of an argument, returns first object for which
block is true. Returns nil if no match is found.
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.


Typing the example into IRb gives an error after the fourth line:
ArgumentError: wrong number of arguments (0 for 1)

Why would that be? Am I missing something? Is the documentation wrong?
What should I be doing?

Ruby 1.8.6 by the way.

Andy J. wrote:

Documentation from here:
http://www.ruby-doc.org/core/classes/Array.html#M000290
[…]
Ruby 1.8.6 by the way.

http://www.ruby-doc.org/core-1.8.6/classes/Array.html#M002201
What you linked are the docs for 1.8.7

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