Exception: EventHook
Overview
Exception-based Event Hooks
Provides an Event Hooks system designed on top of Ruby’s built-in Exception system.
Example
def dothis2
puts 'pre'
hook :quitit
puts 'post'
end
def tryit2
begin
puts "BEFORE"
dothis2
puts "AFTER"
rescue EventHook
event :quitit do
puts "HERE"
end
end
end
tryit2
Instance Attribute Summary collapse
-
#cc ⇒ Object
readonly
Returns the value of attribute cc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name, cc) ⇒ EventHook
constructor
A new instance of EventHook.
Methods inherited from Exception
Constructor Details
#initialize(name, cc) ⇒ EventHook
60 61 62 63 |
# File 'lib/more/facets/eventhook.rb', line 60 def initialize(name, cc) @name = name @cc = cc end |
Instance Attribute Details
#cc ⇒ Object (readonly)
Returns the value of attribute cc.
59 60 61 |
# File 'lib/more/facets/eventhook.rb', line 59 def cc @cc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
59 60 61 |
# File 'lib/more/facets/eventhook.rb', line 59 def name @name end |
Instance Method Details
#call ⇒ Object
64 65 66 |
# File 'lib/more/facets/eventhook.rb', line 64 def call @cc.call end |