Menu Sidebar


Defining #method_missing and #respond_to? at the same time

I was reading Eloquent Ruby yesterday morning (buy a copy if you haven’t already), and it got me thinking about one of my “favorite” Ruby gotchas: defining #method_missing without a corresponding #respond_to?. E.g.:

The resulting code violates the Principle of Least Surprise, and often interacts in unexpected ways with other libraries. I started wondering […]

ActiveRecord association extensions and method_missing

The semantics of method calls in Ruby are simple: Call the named method; or If no method exists, call #method_missing() instead. Normally #send() obeys these rules as well. ActiveRecord association proxies mangle #send()‘s semantics, however, violating the POLS and potentially breaking your code in the process. Let’s say we have some monsters:

Cookie monster, […]

Virtuous Code

"The three virtues of a programmer: laziness, impatience, and hubris" — Larry Wall

Books and Screencasts

RubyTapas Screencasts

RubyTapas Screencasts

Small plates of gourmet Ruby code.

Confident Ruby

Confident Ruby cover

32 Patterns for joyful coding.

The Making of

Confident Ruby cover

Watch me build an app in Sinatra and Rails

Objects on Rails

Objects on Rails

A developer notebook on applying classic Object-Oriented principles to Ruby on Rails projects.

Exceptional Ruby

Exceptional Ruby

The definitive guide to exceptions and failure handling in Ruby.