Array iteration

This is probably more of a style question as I’m coming from Java into
Ruby. I’m used to using an index marker like ‘i’ to assign a value to an
array
index as it loops through.

How is this typically done in Ruby?

For example, this is my inclination in writing a method that takes an
array as argument, iterates through and tests each value, and if the
value meets the criteria, assigns it to another array which will be
returned.

def my_method (array)
new_array = []
i = 0
array.each do |value|
if some_criteria_matches
new_array[i] = value
end
i += 1
end
return my_method
end

Is there a preferred Ruby pattern for this?

use Array#select or Array#grep

Hans M. wrote in post #1152590:

use Array#select or Array#grep

Awesome, I’ll check that out. Thanks!!