0%

ActiveRecord::Calculations speed up Rails app

In general scenarios, calculations that can be done at the database level are not recommended to be done at the Rails app level if there are no special requirements. Avoid unnecessary time, network and resource consumption

ActiveRecord::Calculations provide methods for calculating aggregate values of columns in ActiveRecord models.

Read more »

a ||= b VS a = a || b VS a || a = b, Double Pipe (||) Or Equals (=) in Ruby

A common misconception is that a ||= b is equivalent to a = a || b, but it behaves like a || a = b

In a = a || b, a is set to something by the statement on every run, whereas with a || a = b, a is only set if a is logically false (i.e. if it’s nil or false) because || is ‘short circuiting’. That is, if the left hand side of the || comparison is true, there’s no need to check the right hand side.

Read more »