diff options
author | Claudio B <claudiob@users.noreply.github.com> | 2015-11-20 19:40:35 -0800 |
---|---|---|
committer | Claudio B <claudiob@users.noreply.github.com> | 2015-11-20 19:40:35 -0800 |
commit | 8fcdead070d1c54227ed9c2f2e25e7d38ca03119 (patch) | |
tree | d92c4d660fd6ccc4df4af5de2aedaca83a61a60a /activerecord/lib | |
parent | bf7ab2f92bb63734438609853aaa5dafedfefacd (diff) | |
parent | 7461875be1bc834d23a96bc4448e974d4d1bd11b (diff) | |
download | rails-8fcdead070d1c54227ed9c2f2e25e7d38ca03119.tar.gz rails-8fcdead070d1c54227ed9c2f2e25e7d38ca03119.tar.bz2 rails-8fcdead070d1c54227ed9c2f2e25e7d38ca03119.zip |
Merge pull request #22362 from radar/toggle-documentation
Add example for AR::Persistence#toggle
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 94316d5249..46c6d8c293 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -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 |