Skip to content

Instantly share code, notes, and snippets.

@loganhasson
Last active December 25, 2015 04:29
Show Gist options
  • Save loganhasson/6918054 to your computer and use it in GitHub Desktop.
Save loganhasson/6918054 to your computer and use it in GitHub Desktop.
Mass assign arbitrary attributes on initialization
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