Class: EventBus::CallSlot
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call(*args, &block) ⇒ Object (also: #signal)
- #connect(method = nil, &block) ⇒ Object
- #disconnect! ⇒ Object
-
#initialize(bus, name) ⇒ CallSlot
constructor
A new instance of CallSlot.
- #to_s ⇒ Object
Constructor Details
#initialize(bus, name) ⇒ CallSlot
Returns a new instance of CallSlot.
38 39 40 41 42 |
# File 'lib/ls4/lib/ebus.rb', line 38 def initialize(bus, name) @bus = bus @name = name @method = nil end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
44 45 46 |
# File 'lib/ls4/lib/ebus.rb', line 44 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/ls4/lib/ebus.rb', line 45 def name @name end |
Instance Method Details
#call(*args, &block) ⇒ Object Also known as: signal
61 62 63 64 65 66 67 |
# File 'lib/ls4/lib/ebus.rb', line 61 def call(*args, &block) unless @method raise ::EventBus::SlotError.new("slot not connected", @name) end @bus.ebus_call_log(@method, args, &block) @method.call(*args, &block) end |
#connect(method = nil, &block) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/ls4/lib/ebus.rb', line 47 def connect(method=nil, &block) if @method raise ::EventBus::SlotError.new("slot already connected", @name) end method ||= block @method = method @bus end |
#disconnect! ⇒ Object
56 57 58 59 |
# File 'lib/ls4/lib/ebus.rb', line 56 def disconnect! @method = nil @bus end |
#to_s ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/ls4/lib/ebus.rb', line 71 def to_s m = @method.inspect[/\#\<[^\:]*\:\s?(.+)\>/, 1] unless m m = m.to_s end "#<slot :#{@name} => #{m}>" end |