Class: Soundcloud9000::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/soundcloud9000/events.rb

Instance Method Summary collapse

Constructor Details

#initializeEvents

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