Created
November 29, 2013 07:48
-
-
Save demental/7702679 to your computer and use it in GitHub Desktop.
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 HashMemoize | |
def memoized_value key | |
@memo_hash ||= Hash.new { |hsh, new_key| hsh[new_key] = some_heavy_computation new_key } | |
@memo_hash[key] | |
end | |
private | |
def some_heavy_computation key | |
puts "heavy duty for #{key} !" | |
key * 2 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment