Array.index with block not working

A

Andy Joel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,221
Latest member
TrinidadKa

Latest Threads

Top