Skip to content

Instantly share code, notes, and snippets.

@kenichi
Created March 22, 2012 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenichi/2165047 to your computer and use it in GitHub Desktop.
Save kenichi/2165047 to your computer and use it in GitHub Desktop.
bizzarro dynamic attributes
def method_missing(meth, *args)
meth_s = meth.to_s
key = meth_s.sub(/=$/,'')
aattr = self.account_attributes.find_by_key key
if aattr
case meth_s
when aattr.key
aattr.value
when "#{aattr.key}="
if args[0].nil?
aattr.destroy
else
aattr.value = args[0]
aattr.save!
end
end
elsif meth_s[meth_s.length - 1] == '='
self.account_attributes.create! :key => key, :value => args[0]
else
super(meth, *args)
end
end
@ungoldman
Copy link

bizzarro attribute is bizzarro attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment