Class: RDL::Contract::ProcContract
- Inherits:
-
RDL::Contract
- Object
- RDL::Contract
- RDL::Contract::ProcContract
- Defined in:
- lib/rdl/contracts/proc.rb
Instance Attribute Summary collapse
-
#post_cond ⇒ Object
Returns the value of attribute post_cond.
-
#pre_cond ⇒ Object
Returns the value of attribute pre_cond.
Instance Method Summary collapse
-
#initialize(pre_cond: nil, post_cond: nil) ⇒ ProcContract
constructor
A new instance of ProcContract.
- #to_s ⇒ Object
- #wrap(slf, &blk) ⇒ Object
Constructor Details
#initialize(pre_cond: nil, post_cond: nil) ⇒ ProcContract
Returns a new instance of ProcContract.
5 6 7 8 |
# File 'lib/rdl/contracts/proc.rb', line 5 def initialize(pre_cond:nil, post_cond:nil) @pre_cond = pre_cond @post_cond = post_cond end |
Instance Attribute Details
#post_cond ⇒ Object
Returns the value of attribute post_cond.
3 4 5 |
# File 'lib/rdl/contracts/proc.rb', line 3 def post_cond @post_cond end |
#pre_cond ⇒ Object
Returns the value of attribute pre_cond.
3 4 5 |
# File 'lib/rdl/contracts/proc.rb', line 3 def pre_cond @pre_cond end |
Instance Method Details
#to_s ⇒ Object
21 22 23 |
# File 'lib/rdl/contracts/proc.rb', line 21 def to_s "(#{@pre_cond}) -> (#{@post_cond})" end |
#wrap(slf, &blk) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/rdl/contracts/proc.rb', line 11 def wrap(slf, &blk) Proc.new {|*v, &other_blk| @pre_cond.check(slf, *v, &other_blk) tmp = other_blk ? slf.instance_exec(*v, other_blk, &blk) : slf.instance_exec(*v, &blk) # TODO fix blk # tmp = blk.call(*v, &other_blk) # TODO: Instance eval with self @post_cond.check(slf, tmp, *v, &other_blk) tmp } end |