From: Cali Wildman Date: 2009-05-21T08:37:58+09:00 Subject: Re: gsub choking on fixnum Yukihiro Matsumoto wrote: > Hi, > > In message "Re: gsub choking on fixnum" > on Thu, 21 May 2009 08:08:55 +0900, Cali Wildman > writes: > > |I recently upgrade Ruby from 1.8.5 to 1.8.6. With 1.8.5, gsub handled a > |fixnum just fine but choked on it in 1.8.6. Casting the fixnum to a > |string solved my problem but I'm wondering if this is a bug or it was a > |bug and now it's working as intended or ...? > > Choking code please. > > matz. Here's the code in question, I'm using REXML Document doc = Document.new(entry.embed_code) doc.root.each_element('//embed | //object'){ |elem| elem.attributes['height'] = 140 #this is line 57, see error below elem.attributes['width'] = 170 } The above code generated this error NoMethodError (private method `gsub' called for 140:Fixnum): c:/ruby/lib/ruby/1.8/rexml/text.rb:292:in `normalize' c:/ruby/lib/ruby/1.8/rexml/element.rb:1085:in `[]=' /app/controllers/application.rb:57:in `resize_videos' c:/ruby/lib/ruby/1.8/rexml/element.rb:891:in `each' c:/ruby/lib/ruby/1.8/rexml/xpath.rb:53:in `each' c:/ruby/lib/ruby/1.8/rexml/element.rb:891:in `each' c:/ruby/lib/ruby/1.8/rexml/element.rb:393:in `each_element' /app/controllers/application.rb:56:in `resize_videos' To fix it, I changed it to doc = Document.new(entry.embed_code) doc.root.each_element('//embed | //object'){ |elem| elem.attributes['height'] = 140.to_s elem.attributes['width'] = 170.to_s } I'm hardly an expert on Ruby or REXML, so any insight is much appreciated. -- Posted via http://www.ruby-forum.com/.