A Puzzle for Polite Ruby Programmers

I really enjoyed Jim Weirich’s session on polite programming at the Scottish Ruby Conference. He covered a problem that’s been vexing me for some time, about avoiding the use of method aliasing, by using inheritance instead. Unfortunately, his suggested solution didn’t tell me anything I hadn’t already tried. I still think this must be possible, but that I just don’t know quite enough about Ruby to be able to achieve it. Maybe you do?

Here’s the puzzle:


Can you solve it?

Published by Matt

I write software, and love learning how to do it even better.

Join the Conversation


  1. Here’s my attempt: https://gist.github.com/912526

    Basically, if you use define_method, you can get closure-like behaviour around the method body, since this is defined as a block.

    I suspect this will only work in Ruby 1.9.2 because of some of the restrictions for defining block arguments in earlier versions of Ruby.

    I’m not 100% sure about this solution, but it certainly passes your assertion at the bottom.

Leave a comment

Your email address will not be published. Required fields are marked *