Skip to content

Instantly share code, notes, and snippets.

@brynary
Created August 24, 2009 01:35
Show Gist options
  • Save brynary/173578 to your computer and use it in GitHub Desktop.
Save brynary/173578 to your computer and use it in GitHub Desktop.
module AutoloadMethod
def autoload_method(method_name, filename)
self.instance_eval <<-SRC
def #{method_name}(*args, &block)
require #{filename.inspect}
#{method_name}(*args, &block)
end
SRC
end
end
module ActiveRecord
class Base
extend AutoloadMethod
autoload_method :xss_terminate, "xss_terminate_method"
end
end
puts "Environment loaded. Time to run the app..."
class Post < ActiveRecord::Base
xss_terminate :body
end
$ ruby base.rb
Environment loaded. Time to run the app...
Loading up all of XSS terminate now... (may take awhile...)
Called with: :body
puts "Loading up all of XSS terminate now... (may take awhile...)"
ActiveRecord::Base.class_eval do
def self.xss_terminate(attr)
puts "Called with: #{attr.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment