Created
October 21, 2009 09:30
-
-
Save gumayunov/214991 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
#http://guides.rubyonrails.org/plugins.html | |
module Yaffle | |
def self.included(base) | |
base.send :extend, ClassMethods | |
end | |
module ClassMethods | |
def acts_as_yaffle(options = {}) | |
cattr_accessor :yaffle_text_field | |
self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s | |
send :include, InstanceMethods | |
end | |
end | |
module InstanceMethods | |
def squawk(string) | |
write_attribute(self.class.yaffle_text_field, string.to_squawk) | |
end | |
end | |
end | |
ActiveRecord::Base.send :include, Yaffle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment