Class: Schmetterling::Before
- Inherits:
-
Object
- Object
- Schmetterling::Before
- Defined in:
- lib/schmetterling/before.rb
Instance Method Summary collapse
- #build_module_for_advice(adviced_method, advice) ⇒ Object
-
#initialize(klass, method, advice = nil, &block) ⇒ Before
constructor
A new instance of Before.
Constructor Details
#initialize(klass, method, advice = nil, &block) ⇒ Before
Returns a new instance of Before.
4 5 6 7 |
# File 'lib/schmetterling/before.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/before.rb', line 9 def build_module_for_advice(adviced_method, advice) Module.new do define_method adviced_method do |*args| advice.call(self, *args) super(*args) end end end |