-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_events.rb
108 lines (77 loc) · 1.36 KB
/
base_events.rb
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require_relative 'b_event'
require 'singleton'
module BaseEvents
class EventSetClass < BEvent
attr_reader :events
def initialize(name, *events)
@name = name
@events = events
end
def include?(e)
@events.include? e
end
def inspect
@name
end
end
class Any < BEvent
include Singleton
def initialize
super 'any'
end
def include?(e)
true
end
end
class None < BEvent
include Singleton
def initialize
super "none"
end
def include?(e)
false
end
def to_ary
[]
end
end
class EventsOfClass < BEvent
def initialize(klass)
@klass = klass
end
def ==(other)
other.is_a? @klass
end
def include?(e)
e.is_a? @klass
end
def inspect
@klass.inspect
end
end
class CopyContEvent
def initialize(return_cont)
@return = return_cont
end
def call(arg)
@return.call arg
end
end
def event_set(name, *events)
EventSetClass.new name, events
end
def any
Any.instance
end
def none
None.instance
end
def event_of_class(klass)
EventsOfClass.new klass
end
def copy_cont_event(return_cont)
CopyContEvent.new return_cont
end
module_function :event_set, :any, :none,
:event_of_class, :copy_cont_event
end