我有以下两个变量:替换元素
array = ['h','e','l','l','o']
string = '023'
所有在array
元素没有索引的string
匹配某个地方需要被替换下划线。新阵列应该如下所示:['h','_','l','l','_']
。
我想这样做这样
.map.with_index do |e,i|
if (i != string) #Somehow get it to check the entire string
e = '_'
end
end
你的问题是什么? – sawa 2014-11-06 18:40:07
“023”扩展为“[0,2,3]”还是“[0,23]”?这个问题会得到改善,你可以将它改变为一系列索引。 – 2014-11-06 19:08:08