Ruby Memoization: ||= vs. defined? - Ruby on Rails and Ember.js consultant
02-Jun-2017 3851
In the majority of the Rails applications or even Ruby gems you can find a lot of use cases where you need to memoize a result of some computation for performance benefits and to not compute it again if this result has already been computed. Seems like doing the assignment to some instance variable with ||= operator is the most commonly used solution for this purpose, e.g. @result ||= do_some_heavy_computation. However, there are some cases where it might not produce the expected outome and you should actually use defined? operator instead.
Ruby Memoization: ||= vs. defined? - Ruby on Rails and Ember.js consultant #ruby #rubydeveloper #rubyonrails #Memoization: #defined? #Rails #Ember.js #consultant #ember.js https://www.rubyonrails.ba/link/ruby-memoization-vs-defined-ruby-on-rails-and-ember-js-consultant