gsub! Is modifying unspecified strings
Posted
by user335729
on Stack Overflow
See other posts from Stack Overflow
or by user335729
Published on 2010-06-06T01:08:40Z
Indexed on
2010/06/06
1:12 UTC
Read the original article
Hit count: 289
ruby
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.
© Stack Overflow or respective owner