1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
= Hook Library
Require the hook.rb library.
require 'facets/hook'
Build a class with signals.
class X
include Hook
def course
@course ||= []
end
hook :signal
def boom(event, message)
course << "Kaboom!"
end
signal do |event, message|
course << ["1", event, message]
end
signal do |event, message|
course << ["2", event, message]
end
signal :boom
end
Triger the signal.
x = X.new
x.signal("hi")
The hooks should have been fired.
x.course[0].should == ["1", :signal, "hi"]
x.course[1].should == ["2", :signal, "hi"]
x.course[2].should == "Kaboom!"
x.course[3].should == nil
QED.
---
require 'ae/should'
|