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:
commit
8fcdead070
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue