Class: Pluggaloid::Listener
- Inherits:
-
Object
- Object
- Pluggaloid::Listener
- Defined in:
- lib/pluggaloid/listener.rb
Class Method Summary collapse
-
.cancel! ⇒ Object
プラグインコールバックをこれ以上実行しない。.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
イベントを実行する ==== Args [*args] イベントの引数.
-
#detach ⇒ Object
このリスナを削除する ==== Return self.
-
#initialize(event, &callback) ⇒ Listener
constructor
Args [event] 監視するEventのインスタンス [&callback] コールバック.
Constructor Details
#initialize(event, &callback) ⇒ Listener
Args
- event
-
監視するEventのインスタンス
- &callback
-
コールバック
11 12 13 14 15 |
# File 'lib/pluggaloid/listener.rb', line 11 def initialize(event, &callback) raise Pluggaloid::TypeError, "Argument `event' must be instance of Pluggaloid::Event, but given #{event.class}." unless event.is_a? Pluggaloid::Event @event = event @callback = Proc.new event.add_listener(self) end |
Class Method Details
.cancel! ⇒ Object
プラグインコールバックをこれ以上実行しない。
5 6 |
# File 'lib/pluggaloid/listener.rb', line 5 def self.cancel! throw :plugin_exit, false end |
Instance Method Details
#call(*args) ⇒ Object
イベントを実行する
Args
- *args
-
イベントの引数
20 21 |
# File 'lib/pluggaloid/listener.rb', line 20 def call(*args) @callback.call(*args, &self.class.method(:cancel!)) end |
#detach ⇒ Object
このリスナを削除する
Return
self
26 27 28 |
# File 'lib/pluggaloid/listener.rb', line 26 def detach @event.delete_listener(self) self end |