Chronicling My Ruby on Rails Journey

May 21, 2009

Successful upgrade of Ruby 1.8.5 to 1.8.6

Filed under: rails,ruby rails — Bob Ngu @ 10:03 am
Tags:

In an earlier post, I explained why I didn’t upgrade Ruby to 1.8.6 several months ago, now I bit the bullet and completed the upgrade process, remember this is on the Windows platform which is my development machine.

First, I should mention that I did a fair amount of research as to whether I should upgrade Ruby to 1.8.7 instead and there are concerns on multiple Ruby and Rails forums that there may be backward compatibility issues with 1.8.7, so I decided to stick with 1.8.6. The concern with 1.8.7 is that it has backport of several Ruby 1.9 features causing potential compatibility issues, however there are also developers who don’t think there are any 1.8.7 compatibility issues, so do your own research and decide for yourself the version you wish to upgrade to. My plan is to stick 1.8.6 until 1.9 is certified to be compatible with Rails.

First thing I did was download ruby-1.8.6-p287-i386-mswin32.zip from a pseudo secret Ruby ftp location. This may or may not be obvious but unless someone compiles Ruby for you on Windows, you are out of luck since you don’t have the binaries. Note that it isn’t the latest patch level 368 (as of May 2009) but since I don’t have the Windows binaries for that version, I decided to stick with p287 and also not use one-click installer since it includes an older version of gems which by the way is easily remedied by issuing gem update after the installation. I also heard from Luis Lavena, the creator of the Windows Ruby one click installer, about why he decided to stick with 1.8.6 and not 1.8.7. Here’s his post explaining why he stuck with 1.8.6. BTW, he hasn’t gotten much love from developers in helping him maintain the one click installer, so let’s show him some love and appreciation, he is truly a nice guy and has been very helpful in my past interaction with him.

After downloading the zip file, unzipped the file and copied all folders on top of c:\ruby replacing existing files and folders. And it’s as simple as that to upgrade Ruby except I encountered a problem running my app after the upgrade. Note: unless you use REXML in your app, you won’t get this error and don’t need to apply patch.

I got 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’

I posted the question on ruby-forum and got the Ruby author, Yukihiro “matz” Matsumoto, to respond with the following REXML patch

diff –git a/ChangeLog b/ChangeLog
index b5bd805..1edb627 100644
— a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu May 21 08:50:58 2009 Yukihiro Matsumoto
+
+ * lib/rexml/text.rb (REXML::Text.normalize): call to_s for input.
+ [ruby-talk:337069]
+
Mon May 18 21:40:11 2009 Tanaka Akira

* lib/pathname.rb (Pathname#sub): suppress a warning.
diff –git a/lib/rexml/text.rb b/lib/rexml/text.rb
index 2bc0042..a4a30b6 100644
— a/lib/rexml/text.rb
+++ b/lib/rexml/text.rb
@@ -286,7 +286,7 @@ module REXML
EREFERENCE = /&(?!#{Entity::NAME};)/
# Escapes all possible entities
def Text::normalize( input, doctype=nil, entity_filter=nil )
- copy = input
+ copy = input.to_s
# Doing it like this rather than in a loop improves the speed
#copy = copy.gsub( EREFERENCE, ‘&’ )
copy = copy.gsub( “&”, “&” )

According to him, this is a REXML 1.9 backport that caused the issue, not a gsub bug, and he has committed the changes to 1.8 HEAD. I applied the 1 line change to rexml/text.rb and it worked, much thanks to Matz.

And that’s the story of my successful upgrade of Ruby 1.8.5 to 1.8.6. BTW I also successfully upgraded Rails from 1.2.1 to 2.1 to 2.3.2 but that’s another post for another time.

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.