1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #22362 from radar/toggle-documentation

Add example for AR::Persistence#toggle
This commit is contained in:
Claudio B 2015-11-20 19:40:35 -08:00
commit 8fcdead070

View file

@ -358,6 +358,14 @@ module ActiveRecord
# if the predicate returns +true+ the attribute will become +false+. This
# method toggles directly the underlying value without calling any setter.
# Returns +self+.
#
# Example:
#
# user = User.first
# user.banned? # => false
# user.toggle(:banned)
# user.banned? # => true
#
def toggle(attribute)
self[attribute] = !public_send("#{attribute}?")
self