Method: CommonLib::Array#first_index
- Defined in:
- lib/common_lib/ruby/array.rb
#first_index(value = nil, &block) ⇒ Object
return the first index of the array with a value matching that given
85 86 87 88 89 90 91 |
# File 'lib/common_lib/ruby/array.rb', line 85 def first_index(value = nil, &block) using_block = block_given? each_with_index do |element,index| return index if (using_block && yield(element)) || (value == element) end return nil end |