Created
October 2, 2022 07:06
-
-
Save dogweather/fe67c047e643de4ed34eb40e7b5fcdb0 to your computer and use it in GitHub Desktop.
Example of memoization in Ruby on Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Jurisdiction < ApplicationRecord | |
# ... | |
class << self | |
memoize def find_via(slug:) | |
Jurisdiction.find_by(slug: slug) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment