method
writer_method
writer_method(name, class_name, mapping, allow_nil, conversion)
private
Hide source
# File activerecord/lib/active_record/aggregations.rb, line 173 def writer_method(name, class_name, mapping, allow_nil, conversion) module_eval do define_method("#{name}=") do |part| if part.nil? && allow_nil mapping.each { |pair| self[pair.first] = nil } instance_variable_set("@#{name}", nil) else part = conversion.call(part) unless part.is_a?(class_name.constantize) || conversion.nil? mapping.each { |pair| self[pair.first] = part.send(pair.last) } instance_variable_set("@#{name}", part.freeze) end end end end