module ActiveRecord::Persistence
def toggle(attribute)
user.banned? # => true
user.toggle(:banned)
user.banned? # => false
user = User.first
Example:
Returns +self+.
method toggles directly the underlying value without calling any setter.
if the predicate returns +true+ the attribute will become +false+. This
Assigns to +attribute+ the boolean opposite of attribute?. So
def toggle(attribute) self[attribute] = !public_send("#{attribute}?") self end