在Ruby中的索引位置替换字符

Mar*_*ark 3 ruby indexing position substitution

我有一个字符串,并希望在不同的位置替换多个字符并打印该字符串.

例如

在这里,我喜欢用string_replace替换字符串.

string = "AGACACTTTATATGTAT"

positions = ["2", "5", "8", "10"]

string_replace = ["T", "A", "G", "G"]
Run Code Online (Sandbox Code Playgroud)

我需要的输出是=>"AGTCAATTGAGATGTAT"

我试过这个但没有成功:

positions.zip(string_replace).each do |pos, str|
  string.gsub!(/#{string}[#{pos}]/, '#{str}')
  puts string
end
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

KL-*_*L-7 6

positions.zip(string_replace).each do |pos, str|
  string[pos.to_i] = str
  puts string
end
Run Code Online (Sandbox Code Playgroud)