我的目标是让x
这样x("? world. what ? you say...", ['hello', 'do'])
返回"hello world. what do you say..."
。更多的红宝石方式gsub阵列
我有一些作品,但是从“红宝石路”似乎远:
def x(str, arr, rep='?')
i = 0
query.gsub(rep) { i+=1; arr[i-1] }
end
是否有这样做的更地道的方式? (当然,让我注意速度是最重要的因素。)
首先克隆数组将解决数组销毁问题,如果这是个问题。 – Chuck 2010-06-07 21:44:50