Method: DNApi::Struct#initialize
- Defined in:
- lib/dnapi/struct.rb
#initialize(attrs = {}) ⇒ Struct
Returns a new instance of Struct.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dnapi/struct.rb', line 90 def initialize(attrs = {}) raise(ArgumentError, "#{attrs.inspect} is not a hash") unless attrs.is_a?(Hash) mattrs = attrs.to_mash super(*members.map {|m| mattrs.delete(m) }) self::class._many.each do |assoc| send(:"#{assoc}=", mattrs.delete(assoc) || []) end self::class._ones.each do |assoc| send(:"#{assoc}=", mattrs.delete(assoc) || nil) end mattrs.each do |key, value| send("#{key}=", value) end end |