diff options
author | Ryan Bigg <git@ryanbigg.com> | 2015-11-21 13:20:07 +1100 |
---|---|---|
committer | Ryan Bigg <git@ryanbigg.com> | 2015-11-21 13:22:01 +1100 |
commit | 7461875be1bc834d23a96bc4448e974d4d1bd11b (patch) | |
tree | 813a6d50ddf1cadf323677ef2d7cc780649dc3f5 /activerecord | |
parent | f96b19b6da582bc99dde3f74aeee6ff68353d7c9 (diff) | |
download | rails-7461875be1bc834d23a96bc4448e974d4d1bd11b.tar.gz rails-7461875be1bc834d23a96bc4448e974d4d1bd11b.tar.bz2 rails-7461875be1bc834d23a96bc4448e974d4d1bd11b.zip |
Add example for AR::Persistence#toggle
Diffstat (limited to 'activerecord')
-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 0a6e4ac0bd..6f708182ec 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -355,6 +355,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 |