class << ActiveRecord::Base def acts_as_toggled_date(*attrs) attrs.each do |attr| method_name = attr.to_s.gsub(/(_at|_on)/, '') define_method("#{method_name}?") do !self.send(attr.to_s).blank? end define_method(method_name) do self.update_attribute(attr, Time.now.utc) end define_method("un#{method_name}") do self.update_attribute(attr, '') end end end end