If you pass a block to gsub
instead of a replacement string, it will be yield
ed to for each match, and its result will be used as the replacement string. You can, in that block, increment an index into your array of values, and return the indexed value from the block:
input_values = ['process_date', 'dates']
i = -1
selected_item =
selected_item.gsub(/\(\.\*\)/) {
i += 1
input_values[i]
}.rstrip
Or if you don't care about emptying the input_values array, you could just use shift
:
selected_item = selected_item.gsub(/\(\.\*\)/) { input_values.shift }.rstrip