gsub! Is modifying unspecified strings
- by user335729
I'm extracting some information from an XML file, and I want to perform some modifications on the data while keeping a copy of the original in a variable "origFile". This is what I have:
require "rexml/document"
include REXML
doc = Document.new File.new(thePath)
root = doc.root
array = []
root.elements.each("dict/string") {|element| array << element}
origFile = []
root.elements.each("dict"){|i| origFile << i}
theBody = array[6][0].to_s
theBody.gsub!(/\<!-- more --\>/, "----------Read More----------")
The problem is that after I perform gsub! on theBody, origFile also has the modification. I don't understand why this would be or how to fix it. I would really appreciate your help.