Class: Eventbox::ExternalProc
- Inherits:
-
WrappedProc
- Object
- Proc
- WrappedProc
- Eventbox::ExternalProc
- Defined in:
- lib/eventbox/sanitizer.rb
Overview
Wrapper for Proc objects created external of some Eventbox instance.
External Proc objects can be invoked from event scope through sync_call and yield_call methods. Optionally a proc can be provided as the last argument which acts as a completion callback. This proc is invoked, when the call has finished, with the result value as argument.
class Callback < Eventbox
sync_call def init(&block)
block.call(5, proc do |res| # invoke the block given to Callback.new
p res # print the block result (5 + 1)
end)
end
end
Callback.new {|num| num + 1 } # Output: 6
External Proc objects can also be passed to action or to external scope. In this case a ExternalProc is unwrapped back to an ordinary Proc object.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(object, event_loop, name = nil) ⇒ ExternalProc
constructor
A new instance of ExternalProc.
- #object_for(target_event_loop) ⇒ Object
Constructor Details
#initialize(object, event_loop, name = nil) ⇒ ExternalProc
Returns a new instance of ExternalProc.
329 330 331 332 333 |
# File 'lib/eventbox/sanitizer.rb', line 329 def initialize(object, event_loop, name=nil) @object = object @event_loop = event_loop @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
328 329 330 |
# File 'lib/eventbox/sanitizer.rb', line 328 def name @name end |
Instance Method Details
#object_for(target_event_loop) ⇒ Object
335 336 337 |
# File 'lib/eventbox/sanitizer.rb', line 335 def object_for(target_event_loop) @event_loop == target_event_loop ? @object : self end |