Skip to content

Instantly share code, notes, and snippets.

@altuzar
Created March 8, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altuzar/b203bfb1c3a2fb07029f6b56ea3d38aa to your computer and use it in GitHub Desktop.
Save altuzar/b203bfb1c3a2fb07029f6b56ea3d38aa to your computer and use it in GitHub Desktop.
Memoization Test
require 'memoist'
class Thing
extend Memoist
def a
puts "in a body"
return 10
10
end
memoize :a
def b
puts "in b body"
nil
end
memoize :b
def c
puts "in c body"
10
end
memoize :c
end
tt = Thing.new
2.times do |i|
puts "Iteration: #{i}"
puts tt.a
puts tt.b
puts tt.c
end
# Output:
# Iteration: 0
# in a body
# 10
# in b body
#
# in c body
# 10
# Iteration: 1
# 10
#
# 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment