Module: Ethon::Easies::ResponseCallbacks
- Included in:
- Ethon::Easy
- Defined in:
- lib/ethon/easies/response_callbacks.rb
Overview
This module contains the logic for the response callbacks. The on_complete callback is the only one at the moment.
You can set multiple callbacks, which are then executed in the same order.
easy.on_complete { p 1 }
easy.on_complete { p 2 }
easy.complete
#=> 1
#=> 2
You can clear the callbacks:
easy.on_complete { p 1 }
easy.on_complete { p 2 }
easy.on_complete.clear
easy.on_complete
#=> []
Instance Method Summary collapse
-
#complete ⇒ Object
Execute on_complete callbacks.
-
#on_complete(&block) ⇒ Object
Set on_complete callback.
Instance Method Details
#complete ⇒ Object
Execute on_complete callbacks.
41 42 43 44 45 |
# File 'lib/ethon/easies/response_callbacks.rb', line 41 def complete if defined?(@on_complete) @on_complete.map{ |callback| callback.call(self) } end end |
#on_complete(&block) ⇒ Object
Set on_complete callback.
31 32 33 34 35 |
# File 'lib/ethon/easies/response_callbacks.rb', line 31 def on_complete(&block) @on_complete ||= [] @on_complete << block if block_given? @on_complete end |