set (KirbyBase::KBTable)

    # File lib/kirbybase.rb, line 2246
        def set(recs, data)
            # If updates are not in the form of a Proc, convert updates, which

            # could be an array, a hash, or a Struct into a common format (i.e.

            # hash).

            update_rec = convert_input_data(data) unless data.is_a?(Proc)

            updated_recs = []

            # For each one of the recs that matched the update query, apply the

            # updates to it and write it back to the database table.

            recs.each do |rec|
                temp_rec = rec.dup

                if data.is_a?(Proc)
                    begin
                        data.call(temp_rec)
                    rescue NoMethodError
                        raise 'Invalid field name in code block: %s' % $!
                    end
                 else
                    @field_names.each { |fn| temp_rec[fn] = update_rec.fetch(fn,
                     temp_rec.send(fn)) }
                end

                # Is the user trying to change something they shouldn't?

                raise 'Cannot update recno field!' unless \
                 rec.recno == temp_rec.recno
                raise 'Cannot update internal fpos field!' unless \
                 rec.fpos == temp_rec.fpos
                raise 'Cannot update internal line_length field!' unless \
                 rec.line_length == temp_rec.line_length

                # Are the data types of the updates correct?

                validate_input(temp_rec)

                check_required_fields(temp_rec)

                check_against_input_for_specials(temp_rec)

                # Apply updates to the record and add it to an array holding

                # updated records.  We need the fpos and line_length because

                # the engine will use them to determine where to write the

                # update and whether the updated record will fit in the old

                # record's spot.

                updated_recs << { :rec => @field_names.zip(@field_types
                 ).collect { |fn, ft| convert_to_encoded_string(ft,
                 temp_rec.send(fn)) }, :fpos => rec.fpos,
                 :line_length => rec.line_length }

                # Update any associated blob/memo fields.

                temp_rec.each { |r| r.write_to_file if r.is_a?(KBMemo) } if \
                 @field_types.include?(:Memo)
                temp_rec.each { |r| r.write_to_file if r.is_a?(KBBlob) } if \
                 @field_types.include?(:Blob)
            end

            # Take all of the update records and write them back out to the

            # table's file.

            @db.engine.update_records(self, updated_recs)

            # Return the number of records updated.

            return recs.size
        end