Posted about 7 years ago. Visible to the public.

Memoization [0.4d]


  • Understand what Memoization is and when it can be useful.
  • Understand the @variable ||= computation pattern.
  • Learn how to use the memoized Archive gem.
  • What are the advantages of a gem like memoized over the @variable ||= syntax?
  • Why can it be dangerous to memoize class methods?
    Why is it often fine to memoize instance methods?



Write a class WebsiteSizer that measures the number of characters in the given URL's HTML body:

website_sizer = website_sizer.size_of('') # => 27448 website_sizer.size_of('') # => 2145364

You can use any library to perform the actual HTTP request.

The class should cache its results so subsequent calls for the same URLs return the HTML size instantly, without making an additional HTTP request.

Write two versions of WebsiteSizer:

  1. A version that manually caches the results in some Ruby data structure
  2. A version that caches using the memoized gem.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Henning Koch
Last edit:
26 days ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra Curriculum
This website uses short-lived cookies to improve usability.
Accept or learn more