Last active
March 7, 2017 10:32
-
-
Save pavelz/79c8d9089bf78f601e6e1476c03e7c52 to your computer and use it in GitHub Desktop.
This file contains 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
module Interactors | |
class Base | |
end | |
class ImportantThing < Base | |
@@increment = 0 | |
def initialize(*args) | |
# .... some setup | |
# | |
end | |
def call(*args) | |
@@increment += 1 | |
return "time is #{@@increment}" | |
end | |
end | |
module Memoize | |
def call(*args) | |
@memory ||= super | |
end | |
end | |
end | |
i = Interactors::ImportantThing.new().extend(Interactors::Memoize) | |
a = Interactors::ImportantThing.new() | |
puts 'memoized' | |
puts i.call() | |
puts i.call() | |
puts i.call() | |
puts i.call() | |
puts 'non-memoized' | |
puts a.call() | |
puts a.call() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment