Menu Sidebar


RubyTapas 027: Macros and Modules

In this episode themed after a certain sci-fi television series with the initials “BSG”, we take a look at how to use dynamically generated modules to make metaprogrammed methods open for future extension. This is a two-parter. In part two, (which current subscribers received yesterday), we dig deeper and explore ways to make the generated modules […]

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 […]

Checking the existence of a super method in Ruby

Ruby gives methods the ability to call up to the superclass definition of themselves. Or it may not be a parent class definition; it might call up to a definition in a module included further up the ancestor chain. Either way, it’s an elegant way to build on the functionality of class ancestors. But sometimes […]

Determining Singleton Class Status in Ruby

Q: How do you tell if a given class is an ordinary class or a singleton class? A: Test whether the class is the first element in its own ancestor list.

As you can see, ordinary classes have themselves as first ancestor. Singleton classes do not have themselves as an ancestor.

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.