Menu Sidebar
Menu

Avdi Grimm

Hacker; code documentarian.

method_missing

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.: class Liar def method_missing(*args) “Oops, I lied” end end l = Liar.new l.respond_to?(:foo) # => false l.foo # => “Oops, I lied” […]

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: class 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 Cowsays.com

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.

Archives

Categories