Skip to content

Instantly share code, notes, and snippets.

@pavelz
Last active March 7, 2017 10:32
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 pavelz/79c8d9089bf78f601e6e1476c03e7c52 to your computer and use it in GitHub Desktop.
Save pavelz/79c8d9089bf78f601e6e1476c03e7c52 to your computer and use it in GitHub Desktop.
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