1
1
module Contracts
2
2
module CallWith
3
- def call_with ( this , *args , &blk )
4
- call_with_inner ( false , this , *args , &blk )
3
+ def call_with ( this , *args , ** kargs , &blk )
4
+ call_with_inner ( false , this , *args , ** kargs , &blk )
5
5
end
6
6
7
- def call_with_inner ( returns , this , *args , &blk )
7
+ def call_with_inner ( returns , this , *args , ** kargs , &blk )
8
8
args << blk if blk
9
9
10
10
# Explicitly append blk=nil if nil != Proc contract violation anticipated
11
11
nil_block_appended = maybe_append_block! ( args , blk )
12
12
13
13
# Explicitly append options={} if Hash contract is present
14
- maybe_append_options! ( args , blk )
14
+ kargs_appended = maybe_append_options! ( args , kargs , blk )
15
15
16
16
# Loop forward validating the arguments up to the splat (if there is one)
17
17
( @args_contract_index || args . size ) . times do |i |
@@ -57,14 +57,16 @@ def call_with_inner(returns, this, *args, &blk)
57
57
validator = @args_validators [ args_contracts . size - 1 - j ]
58
58
59
59
unless validator && validator [ arg ]
60
- return unless Contract . failure_callback ( :arg => arg ,
61
- :contract => contract ,
62
- :class => klass ,
63
- :method => method ,
64
- :contracts => self ,
65
- :arg_pos => i -1 ,
66
- :total_args => args . size ,
67
- :return_value => false )
60
+ return unless Contract . failure_callback ( {
61
+ :arg => arg ,
62
+ :contract => contract ,
63
+ :class => klass ,
64
+ :method => method ,
65
+ :contracts => self ,
66
+ :arg_pos => i - 1 ,
67
+ :total_args => args . size ,
68
+ :return_value => false ,
69
+ } )
68
70
end
69
71
70
72
if contract . is_a? ( Contracts ::Func )
@@ -76,15 +78,16 @@ def call_with_inner(returns, this, *args, &blk)
76
78
# If we put the block into args for validating, restore the args
77
79
# OR if we added a fake nil at the end because a block wasn't passed in.
78
80
args . slice! ( -1 ) if blk || nil_block_appended
81
+ args . slice! ( -1 ) if kargs_appended
79
82
result = if method . respond_to? ( :call )
80
83
# proc, block, lambda, etc
81
- method . call ( *args , &blk )
84
+ method . call ( *args , ** kargs , &blk )
82
85
else
83
86
# original method name reference
84
87
# Don't reassign blk, else Travis CI shows "stack level too deep".
85
88
target_blk = blk
86
89
target_blk = lambda { |*params | blk . call ( *params ) } if blk && blk . is_a? ( Contract )
87
- method . send_to ( this , *args , &target_blk )
90
+ method . send_to ( this , *args , ** kargs , &target_blk )
88
91
end
89
92
90
93
unless @ret_validator [ result ]
0 commit comments