Created
March 8, 2018 19:04
-
-
Save altuzar/b203bfb1c3a2fb07029f6b56ea3d38aa to your computer and use it in GitHub Desktop.
Memoization Test
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
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