Created
August 24, 2009 01:35
-
-
Save brynary/173578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby base.rb | |
Environment loaded. Time to run the app... | |
Loading up all of XSS terminate now... (may take awhile...) | |
Called with: :body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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