https://stackoverflow.com/questions/1092675/what-ruby-knowledge-should-i-have
- Everything in Ruby is an expression
- https://stackoverflow.com/questions/9636503/whats-the-difference-of-statement-and-expression-in-ruby
- Closures: Blocks, Procs & Lambdas
- https://blog.appsignal.com/2018/09/04/ruby-magic-closures-in-ruby-blocks-procs-and-lambdas.html
- https://medium.com/podiihq/ruby-blocks-procs-and-lambdas-bb6233f68843
- https://www.rubyguides.com/2016/02/ruby-procs-and-lambdas/
- The yield keyword: https://medium.com/rubycademy/the-yield-keyword-603a850b8921
- Operator Overloading
- http://nicholasjohnson.com/ruby/ruby-course/exercises/operator-overloading/
- https://www.geeksforgeeks.org/operator-overloading-in-ruby/
- https://en.wikipedia.org/wiki/Operator_overloading
- https://www.ruby-lang.org/en/documentation/faq/7/
- Object Attributes in Ruby
- https://rubyinrails.com/2014/03/17/what-is-attr_accessor-in-rails/
- https://stackoverflow.com/questions/4370960/what-is-attr-accessor-in-ruby
- Metaclasses, Class Variables & Class Instance Variables
- https://blog.appsignal.com/2019/02/05/ruby-magic-classes-instances-and-metaclasses.html
- https://rubymonk.com/learning/books/4-ruby-primer-ascent/chapters/39-ruby-s-object-model/lessons/131-singleton-methods-and-metaclasses
- Eager Loading & Avoiding N+1 Queries in Rails
- https://semaphoreci.com/blog/2017/08/09/faster-rails-eliminating-n-plus-one-queries.html
- Lean towards .load.size instead of .count on AR collections. Count always fires a SQL count query. E.g. if we have a view that displays @article.comments.count then iterates through them, we fire 2 queries (one to count, and one to retrieve records). If we say .size instead we still fire 2 queries, but if we iterate first then say .size that's just one query. If we need the size first (say in a view) before the collection itself then .load.size will be the best of both worlds and generate only one DB query. However, if all you need is the count and never actually do anything with the collection, then stick to .count and save RAM by bringing less data back from DB.
- Similarly lean towards .load.any? versus .exists? on AR collections.
- Try to use custom associations over finder methods (and scopes in some cases) as they break preloading. E.g a custom method like latest_alternative_music_article, on Article that looks like self.send("#{article_type}_article").where(category: 'alternative').order(:created_at).last. Let's say we need to iterate through Articles with music topics and display info about each topic. Even if we includes music in the article query, it will still generate N+1 inefficiency. However, if latest_alternative_music_article is declared as a parameterized association instead, preloading is possible to inoculate against N+1.
- The Ruby Object Model
- Inheritance vs. Composition