# Array.index with block not working

**URL:** <https://www.ruby-forum.com/t/array-index-with-block-not-working/143473>\
**Category:** Ruby\
**Created:** [July 19, 2008, 12:20am UTC](https://www.ruby-forum.com/t/array-index-with-block-not-working/143473 "2008-07-19T00:20:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![f2andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7feea3/32.png) [@f2andy](https://www.ruby-forum.com/u/f2andy)\
**Post date:** [July 19, 2008, 12:20am UTC](https://www.ruby-forum.com/t/array-index-with-block-not-working/143473/1 "2008-07-19T00:20:13Z")

</div>

Documentation from here:  
[http://www.ruby-doc.org/core/classes/Array.html#M000290](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.

---

<div class="post-metadata">

**Author:** ![f2andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7feea3/32.png) [@f2andy](https://www.ruby-forum.com/u/f2andy)\
**Post date:** [July 19, 2008, 12:25am UTC](https://www.ruby-forum.com/t/array-index-with-block-not-working/143473/2 "2008-07-19T00:25:42Z")

</div>

Andy J. wrote:

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

> **[Class: Array (Ruby 1.8.6)](https://ruby-doc.org/core-1.8.6/Array.html)**
>
> Class : Array - Ruby 1.8.6

What you linked are the docs for 1.8.7
