Class: Soundcloud9000::Events
- Inherits:
-
Object
- Object
- Soundcloud9000::Events
- Defined in:
- lib/soundcloud9000/events.rb
Instance Method Summary collapse
-
#initialize ⇒ Events
constructor
A new instance of Events.
- #on(event, &block) ⇒ Object
- #trigger(event, *args) ⇒ Object
Constructor Details
#initialize ⇒ Events
Returns a new instance of Events.
3 4 5 |
# File 'lib/soundcloud9000/events.rb', line 3 def initialize @handlers = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#on(event, &block) ⇒ Object
7 8 9 |
# File 'lib/soundcloud9000/events.rb', line 7 def on(event, &block) @handlers[event] << block end |
#trigger(event, *args) ⇒ Object
11 12 13 14 15 |
# File 'lib/soundcloud9000/events.rb', line 11 def trigger(event, *args) @handlers[event].each do |handler| handler.call(*args) end end |