instance method increment

Ruby on Rails 2.3.18

Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

increment(attribute, by = 1)

Initializes attribute to zero if nil and adds the value passed as by (default is 1). The increment is performed directly on the underlying attribute, no setter is invoked. Only makes sense for number-based attributes. Returns self.

Parameters

attribute req
by opt = 1
Source
# File activerecord/lib/active_record/base.rb, line 2696
      def increment(attribute, by = 1)
        self[attribute] ||= 0
        self[attribute] += by
        self
      end

Defined in activerecord/lib/active_record/base.rb line 2696 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Base

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close