Class: ObjectProtocol::Execution
- Inherits:
-
Object
- Object
- ObjectProtocol::Execution
- Defined in:
- lib/object_protocol/execution.rb
Instance Attribute Summary collapse
-
#participants ⇒ Object
readonly
Returns the value of attribute participants.
Instance Method Summary collapse
- #call(protocol) ⇒ Object
-
#initialize(*participants, &blk) ⇒ Execution
constructor
A new instance of Execution.
- #messages ⇒ Object
Constructor Details
#initialize(*participants, &blk) ⇒ Execution
Returns a new instance of Execution.
9 10 11 12 13 14 |
# File 'lib/object_protocol/execution.rb', line 9 def initialize(*participants, &blk) raise(ArgumentError, "#{self.class.name} requires a block") unless block_given? @participants = participants @blk = blk end |
Instance Attribute Details
#participants ⇒ Object (readonly)
Returns the value of attribute participants.
7 8 9 |
# File 'lib/object_protocol/execution.rb', line 7 def participants @participants end |
Instance Method Details
#call(protocol) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/object_protocol/execution.rb', line 16 def call(protocol) begin = false participants.each(&method(:start_spying_on_public_methods_on)) # we guard inside the methods with a global so that we don't start spying # while we're still redefining all the public methods on the participant = true protocol.instance_exec(&blk) ensure = false participants.each(&method(:stop_spying_on_public_methods_on)) end end |
#messages ⇒ Object
30 |
# File 'lib/object_protocol/execution.rb', line 30 def ; ||= []; end |