Reputation: 16339
String = "Test string Test"
array = ["link1","link2"]
How can replace string like this ?
Output should be String = "link1 string link2"
Upvotes: 3
Views: 1685
Reputation: 10874
String#gsub! could return an enumerator, so this is easy:
string.gsub!("Test").each_with_index { |v, i| array[i] }
Upvotes: 10