Exception: EventHook

Inherits:
Exception show all
Defined in:
lib/more/facets/eventhook.rb

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

Instance Method Summary collapse

Methods inherited from Exception

#detail

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

#ccObject (readonly)

Returns the value of attribute cc.



59
60
61
# File 'lib/more/facets/eventhook.rb', line 59

def cc
  @cc
end

#nameObject (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

#callObject



64
65
66
# File 'lib/more/facets/eventhook.rb', line 64

def call
  @cc.call
end