Migration to Ruby 19 and Passenger 1 comments
Over the past few weeks i have been migrating my production application at work to Ruby 1.9. Overall, this has been a fairly straightforward process. After next week, i will probably have the largest Ruby 1.9 production system out there weighing in at a hefty 25,000 lines of Ruby (excluding views).
We are even running the latest SVN Redmine in Ruby 1.9.1 and Rails 2.3.2. Some slight issues here and there, but it mostly works.
Overall the new system tears ass all over the rack. It’s really quite nice. When i combine the new Ruby enhancements with my acts_as_restricted_subdomain updates, my six application servers could probably push ten times as much traffic as before. There is also a massive data migration that will move all of the data from about fifty different databases into one database. Right now we peak at about eight requests a second, so that’s not too bad. I also will be rolling out AirTruk configuration manager across the network for super easy system maintenance. It’s awesome.
There are some notable differences in Ruby 1.9. For instance, you can’t pass an instance variable as a formal parameter in a block. Some of my old views use instance variables to pass the object around, rather than locals, so that was slightly annoying to fix.
Bad: @services.each do | @service|
Good (Still bad): @services.each do |service| ; @service = service
Multibyte character sequences suck. God help us all with internationalization.
I had to find a branch of the fabulous hoptoad_notifier plugin written by Brandon Schwartz that works with Ruby 1.9. Apparently Net::HTTP doesn’t like symbols as parameters any more. Works with strings, though.
New Ruby dates are a problem. Every date is formatted “dd/mm/yyyy” in Ruby 1.9. This sucks for us Americanos since we tend to format things like “mm/dd/yyyy”. There appears to be no simple method for restoring the heuristic behavior or Ruby 1.8 in this regard. I had to make a monkey patch to let my application recognize ‘more normal’ date structures. Also, when you do a difference of two dates it returns something silly like a Rational. Observe:
>> '5/5/2009'.to_date - '5/1/2009'.to_date
=> (4/1)
>> ('5/5/2009'.to_date - '5/1/2009'.to_date).to_io
=> 4
Redmine has a similar issue in the Roadmap, as well.
Strings are subtly different, as well. You can no longer call to_a on a String or iterate over … something with each. You will have to trap those and convert it to an Array manually. Or do something else altogether now.
FasterCSV does not seem to work with Ruby 1.9, so you will have to use the standard CSV gem. It works almost exactly the same except that a lot of the classes like CSV::Writer have been removed, so where you used to: CSV::Writer.generate you now just CSV.generate.

Blog
Wiki
Photo Albums
Authors
Tags
Login
Help

Github
Del.icio.us