Class: Schmetterling::After
- Inherits:
-
Object
- Object
- Schmetterling::After
- Defined in:
- lib/schmetterling/after.rb
Instance Method Summary collapse
- #build_module_for_advice(adviced_method, advice) ⇒ Object
-
#initialize(klass, method, advice = nil, &block) ⇒ After
constructor
A new instance of After.
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 |