Skip to content

Instantly share code, notes, and snippets.

@Kroid
Last active December 9, 2019 12:08
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 Kroid/9c99b0650b06dc100a140d50e215c28d to your computer and use it in GitHub Desktop.
Save Kroid/9c99b0650b06dc100a140d50e215c28d to your computer and use it in GitHub Desktop.
gem interactor - hooks inheritance
class ABC
include Interactor
def self.inherited(klass)
klass.class_eval do
before do
p "doing it"
end
after do
p "done it"
end
end
end
end
class DoIt < ABC
def call
p "calling DoIt"
end
end
DoIt.call

Test case:

require 'interactor'

class ABC
  include Interactor

  before do
    p "doing it"
  end

  after do
    p "done it"
  end
end

class DoIt < ABC
  def call
    p "calling DoIt"
  end
end

DoIt.call

expected:

"doing it"
"calling DoIt"
"done it"

reality:

"calling DoIt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment