Edit and save same xml file ruby



I have written a code that remove comments on xml file, how can i save it as an xml file again. Currently i read the xml file a text file. When i run this code on the console it outputs the xml content, but on the newexample.xml it prints out this : **#<File:0x00000002b8be40>**


here is the code



file = File.open('C:/ruby/example.xml','r+') do |file|
file.each {|line| line.gsub(/^\s\W*\s$/, " ")}

end


File.open("newexample.xml","w") do |f|
f.write file
end

No comments:

Post a Comment