module ForeignKeyMigrations::Schema def self.extended(object) class << object alias_method :define_without_fk, :define unless method_defined?(:define_without_fk) alias_method :define, :define_with_fk end end def define_with_fk ... define_without_fk(...) ... end end ActiveRecord::Schema.extend(ForeignKeyMigrations::Schema)
The code I used to test this technique, which is really the same thing with domain information removed:
module Foo def self.extended(object) class << object alias_method :to_s_without_foo, :to_s unless method_defined?(:to_s_without_foo) alias_method :to_s, :to_s_with_foo end end def to_s_with_foo "#{to_s_without_foo} - got foo!" end end class X end X.extend(Foo) puts X.to_s