I'm trying to replace words (sequence of characters, more generally) in a string with corresponding values in an array. An example is:
"The dimension of the square is {{width}} and {{length}}" with array [10,20] should give
"The dimension of the square is 10 and 20"
I have tried to use gsub as
substituteValues.each do |sub|
value.gsub(/\{\{(.*?)\}\}/, sub)
end
But I could not get it to work. I have also thought of using a hash instead of an array as follows:
{"{{width}}"=>10, "{{height}}"=>20}. I feel this might work better but again, I'm not sure how to code it (new to ruby). Any help is appreciated.