more ruby way of gsub from array
- by aharon
My goal is to let there be x so that x("? world. what ? you say...", ['hello', 'do']) returns "hello world. what do you say...".
I have something that works, but seems far from the "Ruby way":
def x(str, arr, rep='?')
i = 0
query.gsub(rep) { i+=1; arr[i-1] }
end
Is there a more idiomatic way of doing this? (Let me note that speed is the most important factor, of course.)