From 7461875be1bc834d23a96bc4448e974d4d1bd11b Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 21 Nov 2015 13:20:07 +1100 Subject: Add example for AR::Persistence#toggle --- activerecord/lib/active_record/persistence.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord') 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 -- cgit v1.2.3