.increment vs += 1

The source of increment is below, which initializes attribute to zero if nil and adds the value passed as by (default is 1), it does not do save, so .save is still necessary.

def increment(attribute, by = 1)
  self[attribute] ||= 0
  self[attribute] += by
  self
end

Leave a Comment