Class: Protocol::Postcondition
Overview
This class is a proxy that stores postcondition blocks, which are called after the result of the wrapped method was determined.
Instance Method Summary collapse
- #__add__(block) ⇒ Object
- #__check__ ⇒ Object
-
#__result__ ⇒ Object
This is the alternative result “keyword”.
-
#__result__=(result) ⇒ Object
:stopdoc:.
-
#initialize(object) ⇒ Postcondition
constructor
A new instance of Postcondition.
-
#method_missing(*a, &b) ⇒ Object
Send all remaining messages to the object.
-
#myself ⇒ Object
This is the “keyword” to be used instead of
selfto refer to current object. -
#result ⇒ Object
This is the result “keyword” which can be used to query the result of wrapped method in a postcondition clause.
Constructor Details
#initialize(object) ⇒ Postcondition
Returns a new instance of Postcondition.
9 10 11 12 |
# File 'lib/protocol/post_condition.rb', line 9 def initialize(object) @object = object @blocks = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*a, &b) ⇒ Object
Send all remaining messages to the object.
53 54 55 |
# File 'lib/protocol/post_condition.rb', line 53 def method_missing(*a, &b) @object.__send__(*a, &b) end |
Instance Method Details
#__add__(block) ⇒ Object
46 47 48 49 |
# File 'lib/protocol/post_condition.rb', line 46 def __add__(block) @blocks << block self end |
#__check__ ⇒ Object
42 43 44 |
# File 'lib/protocol/post_condition.rb', line 42 def __check__ @blocks.all? { |block| instance_eval(&block) } end |
#__result__ ⇒ Object
This is the alternative result “keyword”.
15 16 17 |
# File 'lib/protocol/post_condition.rb', line 15 def __result__ @result end |
#__result__=(result) ⇒ Object
:stopdoc:
38 39 40 |
# File 'lib/protocol/post_condition.rb', line 38 def __result__=(result) @result = result end |
#myself ⇒ Object
This is the “keyword” to be used instead of self to refer to current object.
33 34 35 |
# File 'lib/protocol/post_condition.rb', line 33 def myself @object end |
#result ⇒ Object
This is the result “keyword” which can be used to query the result of wrapped method in a postcondition clause.
21 22 23 24 25 26 27 28 29 |
# File 'lib/protocol/post_condition.rb', line 21 def result if @object.respond_to? :result warn "#{@object.class} already defines a result method, "\ "try __result__ instead" @object.__send__(:result) else @result end end |