Class: Fantasy::Event::Event
- Inherits:
-
Object
- Object
- Fantasy::Event::Event
- Defined in:
- lib/fantasy-irc/events.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call(args = nil) ⇒ Object
-
#initialize(name) ⇒ Event
constructor
A new instance of Event.
- #register(&callback) ⇒ Object
Constructor Details
#initialize(name) ⇒ Event
Returns a new instance of Event.
36 37 38 39 40 |
# File 'lib/fantasy-irc/events.rb', line 36 def initialize(name) puts "New Event with name #{name}" @name = name @callbacks = Hash.new end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/fantasy-irc/events.rb', line 34 def name @name end |
Instance Method Details
#call(args = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/fantasy-irc/events.rb', line 49 def call(args=nil) if @callbacks.empty? then return end @callbacks.each { |uuid, proc| proc.call(args) } end |
#register(&callback) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/fantasy-irc/events.rb', line 42 def register(&callback) uuid = SecureRandom.uuid() @callbacks[uuid] = callback puts "#{self}: registered callback #{callback} with uuid #{uuid}." end |