Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment