Prev: [ANN] Inochi 2.0.0
Next: Preferred state machine gem?
From: =?ISO-8859-1?Q?Une_B=E9vue?= on 25 Apr 2010 04:53 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 ? -- � 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)
From: Brian Candler on 25 Apr 2010 05:20 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/.
From: =?ISO-8859-1?Q?Une_B=E9vue?= on 25 Apr 2010 05:46 Brian Candler <b.candler(a)pobox.com> 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)
From: =?ISO-8859-1?Q?Une_B=E9vue?= on 25 Apr 2010 06:23 Une B�vue <unbewusst.sein(a)google.com.invalid> wrote: > then, no workaround ? I've found a working one, not using "REXML::Formatters::Pretty.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)
|
Pages: 1 Prev: [ANN] Inochi 2.0.0 Next: Preferred state machine gem? |