Class: Schmetterling::After

Inherits:
Object
  • Object
show all
Defined in:
lib/schmetterling/after.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, method, advice = nil, &block) ⇒ After

Returns a new instance of After.



4
5
6
7
# File 'lib/schmetterling/after.rb', line 4

def initialize(klass, method, advice=nil, &block)
  advice ||= block
  klass.send(:prepend, build_module_for_advice(method, advice))
end

Instance Method Details

#build_module_for_advice(adviced_method, advice) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/schmetterling/after.rb', line 9

def build_module_for_advice(adviced_method, advice)
  Module.new do
    define_method adviced_method do |*args|
      super(*args)
      advice.call(self, *args)
    end
  end
end