Louis J Scoras
2/20/2007 10:02:00 PM
On 2/20/07, Jim Bob <james_b@anytimenow.com> wrote:
>
> Thanks for your help, sometimes best just to program an old fashion for
> loop ;)
Nahh, more abstraction is a good thing =)
require 'enumerator'
class Array
def find_my_index(x,y)
to_enum(:each_with_index).each_cons(2) {|(a,i),(b,_)|
return i if a == x && b == y
}
nil
end
end
And then it's just:
ary = [43,21,56,12,93,12]
puts ary.find_my_index(12,93) # => 3
puts ary.find_my_index(93,12) # => 4
puts ary.find_my_index(56,100) # => nil
--
Lou.