Method: Struct#assign_attributes
- Defined in:
- lib/casual_support/struct/assign_attributes.rb
#assign_attributes(new_attributes) ⇒ self
Assigns values in the given Hash to corresponding attributes of the Struct. Both Symbol keys and String keys are accepted. Keys which don’t correspond to an attribute of the Struct are ignored. Mutates the Struct and returns it.
16 17 18 19 20 21 22 23 |
# File 'lib/casual_support/struct/assign_attributes.rb', line 16 def assign_attributes(new_attributes) ms = self.members new_attributes.each do |k, v| m = k.to_sym self[m] = v if ms.include?(m) end self end |