Last active
December 25, 2015 04:29
-
-
Save loganhasson/6918054 to your computer and use it in GitHub Desktop.
Mass assign arbitrary attributes on initialization
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 Person | |
attr_accessor :name, :birthday, :hair_color, :eye_color, :height, :weight, | |
:handed, :complexion, :t_shirt_size, :wrist_size, :glove_size, | |
:pant_length, :pant_width | |
def initialize(data) | |
data.each do |attrib, value| | |
self.send("#{attrib}=", value) unless !self.respond_to?(attrib.to_sym) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment