Skip to content

Instantly share code, notes, and snippets.

@zlw
Created June 9, 2012 14:38
Show Gist options
  • Save zlw/2901210 to your computer and use it in GitHub Desktop.
Save zlw/2901210 to your computer and use it in GitHub Desktop.
class Product < ActiveRecord::Base
[:price, :weight].each do |e|
define_method e do
data && data[e.to_s]
end
define_method :"#{e}=" do |val|
self.data = (data || {}).merge(e => val)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment