Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Rexml pretty printing "can't modify frozen string"

Reply
Thread Tools

Rexml pretty printing "can't modify frozen string"

 
 
Une Bévue
Guest
Posts: n/a
 
      04-25-2010

i want to use (ruby 1.9) Formatters:retty 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:retty.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 ?
--
« Il y a tellement de choses plus importantes dans la vie que l'argent,
mais il faut tellement d'argent pour les acquérir. »
(Groucho Marx)
 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      04-25-2010
Une Bévue wrote:
> 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:

>> s = "aaa".freeze

=> "aaa"
>> s.gsub!(/b/,'')

=> nil

This is different from the behaviour of squeeze!

>> s.squeeze!

TypeError: can't modify frozen string
from (irb):17:in `squeeze!'
from (irb):17
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Une Bévue
Guest
Posts: n/a
 
      04-25-2010
Brian Candler <(E-Mail Removed)> wrote:

> 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 ?
--
« Il y a tellement de choses plus importantes dans la vie que l'argent,
mais il faut tellement d'argent pour les acquérir. »
(Groucho Marx)
 
Reply With Quote
 
Une Bévue
Guest
Posts: n/a
 
      04-25-2010
Une Bévue <(E-Mail Removed)> wrote:

> then, no workaround ?


I've found a working one, not using "REXML::Formatters:retty.new 2",
see :
<http://snippets.dzone.com/posts/show/4953> DZone Snippets - Pretty
Print XML using Ruby
--
« Il y a tellement de choses plus importantes dans la vie que l'argent,
mais il faut tellement d'argent pour les acquérir. »
(Groucho Marx)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling xpython: No rule to make target `runathana.py', needed by `frozen/frozen.c'. est Python 1 10-11-2010 03:35 AM
Re: One more Pretty Face - Pretty face9.jpg [1/1] Harvey Digital Photography 7 11-04-2004 09:53 AM
Frozen string problem, but I haven't frozen anything? LC Geldenhuys Ruby 5 02-18-2004 08:13 AM
Re: Pretty Please Peer2Peer need help Pretty Please John Haithwaite @ Blue Case Solutions Computer Support 0 07-06-2003 10:20 PM
Re: Pretty Please Peer2Peer need help Pretty Please Ralph Wade Phillips Computer Support 0 07-06-2003 09:07 PM



Advertisments