Module: Seh::EventTarget
- Included in:
- Default
- Defined in:
- lib/seh/event_target.rb
Defined Under Namespace
Classes: Default
Instance Method Summary collapse
Instance Method Details
#bind(event_type = nil, &block) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/seh/event_target.rb', line 6 def bind event_type=nil, &block raise "expected a block" unless block_given? @_binds ||= [] bind = EventBind.new event_type, &block @_binds << bind EventBindDisconnector.new ->{ @_binds.delete bind; nil } end |
#bind_once(event_type = nil, &block) ⇒ Object
14 15 16 17 |
# File 'lib/seh/event_target.rb', line 14 def bind_once event_type=nil, &block return unless block_given? bind_disconnector = self.bind(event_type) { |event| bind_disconnector.disconnect; block.call event } end |