Skip to content

Instantly share code, notes, and snippets.

@demental
Created November 29, 2013 07:48
Show Gist options
  • Save demental/7702679 to your computer and use it in GitHub Desktop.
Save demental/7702679 to your computer and use it in GitHub Desktop.
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