Returns an instance of the specified klass with the attributes
of the current record. This is mostly useful in relation to single-table
inheritance structures where you want a subclass to appear as the
superclass. This can be used along with record identification in Action
Pack to allow, say, Client < Company to do something like
render partial: @client.becomes(Company) to render that
instance using the companies/company partial instead of clients/client.

Note: The new instance will share a link to the same attributes as the
original class. Therefore the sti column value will still be the same. Any
change to the attributes on either instance will affect both instances. If
you want to change the sti column as well, use becomes! instead.

Initializes attribute to zero if nil and
subtracts the value passed as by (default is 1). The decrement
is performed directly on the underlying attribute, no setter is invoked.
Only makes sense for number-based attributes. Returns self.

Wrapper around decrement
that saves the record. This method differs from its non-bang version in the
sense that it passes through the attribute setter. Saving is not subjected
to validation checks. Returns true if the record could be
saved.

Initializes attribute to zero if nil and adds the
value passed as by (default is 1). The increment is performed
directly on the underlying attribute, no setter is invoked. Only makes
sense for number-based attributes. Returns self.

Wrapper around increment
that saves the record. This method differs from its non-bang version in
that it passes through the attribute setter. Saving is not subjected to
validation checks. Returns true if the record could be saved.

def with_optimistic_retry
begin
yield
rescue ActiveRecord::StaleObjectError
begin
# Reload lock_version in particular.
reload
rescue ActiveRecord::RecordNotFound
# If the record is gone there is nothing to do.
else
retry
end
end
end

If the model is new, a record gets created in the database, otherwise the
existing record gets updated.

By default, save always runs validations. If any of them fail the action is
cancelled and save returns
false, and the record won't be saved. However, if you
supply validate: false, validations are bypassed altogether. See ActiveRecord::Validations for more information.

By default, save also sets the
updated_at/updated_on attributes to the current
time. However, if you supply touch: false, these timestamps
will not be updated.

There's a series of callbacks associated with save. If any of the
before_* callbacks throws :abort the action is
cancelled and save returns
false. See ActiveRecord::Callbacks for further details.

Attributes marked as readonly are silently
ignored if the record is being updated.

Assigns to attribute the boolean opposite of
attribute?. So if the predicate returns true the
attribute will become false. This method toggles directly the
underlying value without calling any setter. Returns self.

Wrapper around toggle that
saves the record. This method differs from its non-bang version in the
sense that it passes through the attribute setter. Saving is not subjected
to validation checks. Returns true if the record could be
saved.

Saves the record with the updated_at/on attributes set to the current time
or the time specified. Please note that no validation is performed and only
the after_touch, after_commit and
after_rollback callbacks are executed.

This method can be passed attribute names and an optional time argument. If
attribute names are passed, they are updated along with updated_at/on
attributes. If no time argument is passed, the current time is used as
default.

# File activerecord/lib/active_record/persistence.rb, line 262defupdate(attributes)
# The following transaction covers any possible database side-effects of the# attributes assignment. For example, setting the IDs of a child collection.with_transaction_returning_statusdoassign_attributes(attributes)
saveendend

# File activerecord/lib/active_record/persistence.rb, line 275defupdate!(attributes)
# The following transaction covers any possible database side-effects of the# attributes assignment. For example, setting the IDs of a child collection.with_transaction_returning_statusdoassign_attributes(attributes)
save!endend