Rexml pretty printing "can't modify frozen string"

U

Une Bévue

i want to use (ruby 1.9) Formatters::pretty and i get the error :
/opt/local/lib/ruby1.9/1.9.1/rexml/formatters/pretty.rb:90:in
`squeeze!': can't modify frozen string (RuntimeError)

then, i look if my strings are frozen :

doc = Document.new('<html></html>',{:raw=>:all})
[...]
fmt = Formatters::pretty.new 2
s = String.new
puts s.frozen?
puts doc.frozen?
docs = doc.dup
puts docs.frozen?
fmt.write(docs, s)
puts s

for all s, doc and docs i get false to #.frozen?
what isn't working here ?
 
B

Brian Candler

Une said:
for all s, doc and docs i get false to #.frozen?
what isn't working here ?

An object might not be frozen, but one of the objects it contains
(directly or indirectly) could be.

Looking at the source line which raised the error, the String which is
being squeezed is something returned by node.to_s

Interestingly, the line before does a gsub!, and it seems that this is
happy on a frozen string as long as no change is required:
=> nil

This is different from the behaviour of squeeze!
TypeError: can't modify frozen string
from (irb):17:in `squeeze!'
from (irb):17
 
U

Une Bévue

Brian Candler said:
An object might not be frozen, but one of the objects it contains
(directly or indirectly) could be.

yes right !
Looking at the source line which raised the error, the String which is
being squeezed is something returned by node.to_s

then, no workaround ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top