Skip to content

Instantly share code, notes, and snippets.

@texel
Created June 25, 2009 18:23
Show Gist options
  • Select an option

  • Save texel/136054 to your computer and use it in GitHub Desktop.

Select an option

Save texel/136054 to your computer and use it in GitHub Desktop.
module TimeAttributeExtensions
module ClassMethods
def define_attribute_methods
if super
columns_hash.each do |name, column|
if [:datetime, :timestamp].include?(column.type)
define_method("#{name}=") do |time|
super parse_time_from_hash(time)
end
end
end
return true
end
end
end
module InstanceMethods
def parse_time_from_hash(time)
# Do time parsing here
end
end
def self.included(receiver)
receiver.send(:include, InstanceMethods)
receiver.extend ClassMethods
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment