Guest User

Untitled

a guest
Mar 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. require 'memoist'
  2. class Thing
  3. extend Memoist
  4. def a
  5. puts "in a body"
  6. return 10
  7. 10
  8. end
  9. memoize :a
  10.  
  11. def b
  12. puts "in b body"
  13. nil
  14. end
  15. memoize :b
  16.  
  17. def c
  18. puts "in c body"
  19. 10
  20. end
  21. memoize :c
  22. end
  23.  
  24. tt = Thing.new
  25. 2.times do |i|
  26. puts "Iteration: #{i}"
  27. puts tt.a
  28. puts tt.b
  29. puts tt.c
  30. end
  31.  
  32. # Output:
  33. # Iteration: 0
  34. # in a body
  35. # 10
  36. # in b body
  37. #
  38. # in c body
  39. # 10
  40. # Iteration: 1
  41. # 10
  42. #
  43. # 10
Add Comment
Please, Sign In to add comment