Skip to content

Instantly share code, notes, and snippets.

@brunofrank
Last active May 8, 2018 02:02
Show Gist options
  • Save brunofrank/9712bbfbc50488e5bb031f5201025558 to your computer and use it in GitHub Desktop.
Save brunofrank/9712bbfbc50488e5bb031f5201025558 to your computer and use it in GitHub Desktop.
class ActiveRecord::Base
def self.has_custom_fields(store_at, *custom_fields)
custom_fields.each.each do |name|
define_method name do
self[store_at][name]
end
define_method "#{name}=" do |new_value|
self[store_at][name] = new_value
end
end
end
class Contact
has_custom_fields :custom_fields, :age, :fruta, :cor_do_cabelo
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment