Last active
December 26, 2015 16:48
-
-
Save cnocon/7182103 to your computer and use it in GitHub Desktop.
For blog post on memoization and recursion
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
| # When this method is called on any class instance, | |
| # the method will reconstruct the string every time. | |
| def user_full_name | |
| "#{first_name} #{last_name}" | |
| end | |
| # By memoizing the call, we store the string with the | |
| # object that is the class instance. Below is a classic | |
| # example of memoization in code: | |
| def user_full_name | |
| @user_full_name ||= "#{first_name} #{last_name}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment