Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Freeze memoized results when instance is frozen instead of immediatel…
…y so you can memoize mutable objects
- Loading branch information
Showing
1 changed file
with
3 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
6c70c02
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What issues did you run into with freezing memoized returned values? I think it would be smart to stop others from modifying the cache.
def hello; “Hello”; end
memoize :hello
hello #=> “Hello”
hello.gsub!(“.*”, “b00m”)
hello #=> “b00m”
We could dup the returning value, but what a waste of time.