Class: Flirt::Callback
- Inherits:
-
Object
- Object
- Flirt::Callback
- Defined in:
- lib/flirt/callback.rb
Instance Attribute Summary collapse
-
#callback_name ⇒ Object
Returns the value of attribute callback_name.
-
#callback_object_id ⇒ Object
Returns the value of attribute callback_object_id.
-
#object ⇒ Object
Returns the value of attribute object.
-
#weakref ⇒ Object
Returns the value of attribute weakref.
Instance Method Summary collapse
- #==(other_callback) ⇒ Object
- #alive? ⇒ Boolean
- #call(event_data) ⇒ Object
-
#initialize(opts = {}) ⇒ Callback
constructor
A new instance of Callback.
Constructor Details
#initialize(opts = {}) ⇒ Callback
Returns a new instance of Callback.
12 13 14 15 16 17 18 |
# File 'lib/flirt/callback.rb', line 12 def initialize(opts = {}) self.callback_name = opts.fetch(:callback_name) callback_object = opts.fetch(:object) self.weakref = !!opts[:weakref] self.object = weakref ? WeakRef.new(callback_object) : callback_object self.callback_object_id = callback_object.object_id end |
Instance Attribute Details
#callback_name ⇒ Object
Returns the value of attribute callback_name.
10 11 12 |
# File 'lib/flirt/callback.rb', line 10 def callback_name @callback_name end |
#callback_object_id ⇒ Object
Returns the value of attribute callback_object_id.
10 11 12 |
# File 'lib/flirt/callback.rb', line 10 def callback_object_id @callback_object_id end |
#object ⇒ Object
Returns the value of attribute object.
10 11 12 |
# File 'lib/flirt/callback.rb', line 10 def object @object end |
#weakref ⇒ Object
Returns the value of attribute weakref.
10 11 12 |
# File 'lib/flirt/callback.rb', line 10 def weakref @weakref end |
Instance Method Details
#==(other_callback) ⇒ Object
33 34 35 36 |
# File 'lib/flirt/callback.rb', line 33 def ==(other_callback) callback_object_id == other_callback.callback_object_id && callback_name == other_callback.callback_name end |
#alive? ⇒ Boolean
27 28 29 30 |
# File 'lib/flirt/callback.rb', line 27 def alive? return true unless weakref object.weakref_alive? end |
#call(event_data) ⇒ Object
21 22 23 24 |
# File 'lib/flirt/callback.rb', line 21 def call(event_data) return unless alive? object.send callback_name, event_data end |