Created
June 18, 2014 09:09
-
-
Save jin/dbc0fb92d384a68cc7f1 to your computer and use it in GitHub Desktop.
better way of organizing attributes in ruby models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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