module ActiveRecord::Persistence::ClassMethods
def build(attributes = nil, &block)
u.is_admin = false
User.build([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) do |u|
# Building an Array of new objects using a block, where the block is executed for each object:
end
u.is_admin = false
User.build(first_name: 'Jamie') do |u|
# Build a single object and pass it into a block to set other attributes.
User.build([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }])
# Build an Array of new objects
User.build(first_name: 'Jamie')
# Build a single new object
==== Examples
attributes on the objects that are to be built.
The +attributes+ parameter can be either a Hash or an Array of Hashes. These Hashes describe the
objects.
Builds an object (or multiple objects) and returns either the built object or a list of built
def build(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| build(attr, &block) } else new(attributes, &block) end end