A Ruby Meta-Programming Riddle

When we were at Scotland on Rails (excellent conference by the way, you should definitely go), and we sat in Dave Thomas’ keynote, where he talked about the “Ruby Object Model”, funnily enough we ran across a meta-programming wonder in that very session. It has been keeping me busy for a couple of hours, and I’d like to share my revelations. With some of them I’m not completely in the clear, but maybe they’ll be a start for discussion. It’s more a tale of one of my adventure through the Ruby object model than a fancy tutorial, so if you’re up for that kind of thing, keep going. If not, just keep on reading.

Ruby 1.9 Upgrading Woes

Actually, not so much woes, as general musings. I just finished upgrading a project I’ve been maintaining for the last 15 months or so to Ruby 1.9, and I thought I’d share some of my experiences with the process. Looking back it wasn’t so hard after all, but there were some pitfalls.

Remembering super

Yehuda Katz recently wrote a post about good old super, probably one of the most underused keywords in Ruby, sadly enough. What can I say, it hit right home. It pretty much nailed what’s wrong with alias_method_chain, and pretty much put in words how I felt about it too. It helped to explain why I get a weird feeling in my stomach when I see how plugins like authlogic implement some of their functionality. To sum up: it just feels wrong.

The Curious Case Of The Bang Method

One of the cool things about Ruby is the possibility to make your method’s intent more expressive using the question mark or the bang. There’s no need to argue about the use of the question mark method, their intent is to ask something, whether it’s the the status of an object or if the current weather is suitable for getting out your longboard. Their result will usually be true or false, including nil or not nil.

run_later Gets Some Rails 2.3 Middleware Love

Apart from the awesome new features for users of the framework, Rails 2.3 got a lot of love on the inside too. It’s no secret it’s running on Rack now, and that switch made some of the internal code a lot easier on the eyes. They also added a Rails-internal middleware stack, on which some of the framework’s functionality builds already.