Rails Migration Class

I was just poking around in ActiveRecord::Migration. It’s a slick little class:

1
2
3
4
5
6
7
8
9
10
11
12
class Migration
  class << self
    def up() end
    def down() end

    private
      def method_missing(method, *arguments, &block)
        arguments[0] = Migrator.proper_table_name(arguments.first) unless arguments.empty?
        ActiveRecord::Base.connection.send(method, *arguments, &block)
      end
  end
end

What I find so cool about it is that it just uses method\_missing and send to send along the method to ActiveRecord::Base.connection rather than mixing in or subclassing.

Advertisements

1 Response to “Rails Migration Class”


  1. 1 Mark Aufflick January 6, 2006 at 7:45 pm

    I’m not too familiar with Ruby (yet), but the unknown message passing has similar properties to AUTOLOAD in Perl.

    It *feels* cool. At first. Then it hunts you down with it’s indirect, hard to profile, hard to trace nastiness. Madness lies therein.

    Mixins and subclasses OTOH are the good way to do things.

    Every so often you come across a problem where the ability to forward on unknown messages is a Godsend, enabling you to do things that would have otherwise been far more complicated, but my strong advice is to use mixins and subclassing where you can achieve the same end.


Comments are currently closed.



Pages

Categories

Copyright ©2008-2013 James E Orchard-Hays, All Rights Reserved

%d bloggers like this: