Skip to content

Instantly share code, notes, and snippets.

@jin
Created June 18, 2014 09:09
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 jin/dbc0fb92d384a68cc7f1 to your computer and use it in GitHub Desktop.
Save jin/dbc0fb92d384a68cc7f1 to your computer and use it in GitHub Desktop.
better way of organizing attributes in ruby models
class User
PROPERTIES = [:id, :name, :email]
PROPERTIES.each { |prop|
attr_accessor prop
}
def initialize(attributes = {})
attributes.each { |key, value|
self.send("#{key}=", value) if PROPERTIES.member? key
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment