Skip to content

Instantly share code, notes, and snippets.

@gumayunov
Created October 21, 2009 09:30
Show Gist options
  • Save gumayunov/214991 to your computer and use it in GitHub Desktop.
Save gumayunov/214991 to your computer and use it in GitHub Desktop.
#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