A sketched picture of James' head

James Smith

Building a better future out of code

Running Mephisto on Ruby 1.8.7

Posted by

My server runs Ubuntu, and seeing as 8.10 (Intrepid Ibex) is out, I thought "woo, let's upgrade". Bad idea. Well, partly. Most of the upgrade went fine, but there was one problem. Intrepid comes with Ruby 1,8.7, which works fine with Rails >=2.1, but doesn't work with anything lower. Mephisto, on the other hand, doesn't work with Rails 2.1 yet, and is only usable with Rails

NoMethodError (undefined method `[]' for #<:enumerator:0x2aaaad5f7a58>)

So, I was faced with having to downgrade to Ruby 1.8.6 (a royal pain as Intrepid doesn't provide packages for it), or "fix" Mephisto to work with 2.1 (oh my god, don't even get me started). Fortunately, another solution presented itself.

I came across this blog post which describes the problem I was having. The gist (it's in Spanish) is that the main problem with Rails 2.0.2 and Ruby 1.8.7 is that Ruby 1.8.7 has added a String#chars function to the core language. Rails also adds this function, but the two have different return types, hence causing much breakage. The solution? Remove Ruby's String#chars and let Rails do its thing. Add this code to an initializer in your Rails 2.0.2 app, and it will work (better, at least) with Ruby 1.8.7.

begin String.class_eval { remove_method :chars } rescue NameError end

As you can tell by the fact that you're reading this blog, it works a treat. Hurrah!

EDIT: Another solution, which I only just worked out, would be to install the very badly-named Ruby Enterprise Edition, which sits alongside the system's Ruby and is call-compatible with 1.8.6. This makes a lot of sense if you're using passenger (mod_rails), as well.

Comments

Add a comment