bench for this 
```ruby
class Array
  def index(obj = nil, &block)
    return self.enum_for(:index) if !obj && !block
    i = 0
    while i < self.length
      return i if obj ? (self[i] == obj) : block.call(self[i])
      i += 1
    end
    nil
  end

  def index2(obj = nil, &block)
    return self.enum_for(:index) if !obj && !block
    self.each_with_index do |e, i|
      return i if obj ? (e == obj) : block.call(e)
    end
    nil
  end
end

x = (0..100000).to_a

tm = Time.now
10000.times{ x.index(12345) }
puts Time.now - tm

tm = Time.now
10000.times{ x.index2(12345) }
puts Time.now - tm
```

```
0.493349075317
1.31645393372
```