Skip to content

Instantly share code, notes, and snippets.

@ak47
Created June 5, 2012 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ak47/2876886 to your computer and use it in GitHub Desktop.
Save ak47/2876886 to your computer and use it in GitHub Desktop.
module ActsAsCatchall
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
class << self; attr_accessor :catchall end
def acts_as_catchall(options = {})
# db_field, klass, use_method_missing = false
@catchall = options[:db_field]
serialize @catchall, options[:klass]
if options[:use_method_missing]
class_eval <<-EOV
include ActsAsCatchall::InstanceMethods
EOV
end
end
end
module InstanceMethods
def method_missing(method, *args)
# puts @catchall
puts self.respond_to?(:catchall)
puts self.class.respond_to?(:catchall)
end
end
end
ActiveRecord::Base.class_eval { include ActsAsCatchall }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment