Class: Proc
- Inherits:
-
Object
- Object
- Proc
- Defined in:
- lib/on/proc.rb
Overview
Syntatic sugar for creating an on
callback from Proc.
Example
require 'on/proc'
def tweet(, &block)
callback = block.on(:success, :failure)
callback.call :success
rescue => e
callback.call :failure, e.
end
tweet "hello world" do |callback|
callback.on :success do
# handle success
end
callback.on :failure do ||
# handle error message
end
end
Instance Method Summary collapse
Instance Method Details
#on(*callbacks) ⇒ Object
25 26 27 |
# File 'lib/on/proc.rb', line 25 def on(*callbacks) On.new(*callbacks, &self) end |