56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/coderunner/heuristic_run_methods.rb', line 56
def try_by_system(expected_return=NilClass, &block)
@@system_triers ||= rcp.system_run_classes.inject({}){|hash, run_class|
log hash.class
hash[run_class] = run_class.new(@runner).learn_from(self).freeze
hash}
answer = nil
if @@successful_trial_class
begin
answer = yield(@@system_triers[@@successful_trial_class].dup, self)
raise CRError.new("trial returned an answer, but answer was not of the right class") unless expected_return == NilClass or answer.is_a? expected_return
return answer
rescue => err
log err
end
end
@@system_triers.values.each do |trier|
begin
answer = yield(trier.dup, self)
raise CRError.new("trial returned an answer, but answer was not of the right class") unless expected_return == NilClass or answer.is_a? expected_return
@@successful_trial_system = trier.class.run_sys_name
@@successful_trial_class = trier.class
return answer
rescue Errno::ENOENT, TypeError, CRMild, CRError => err
next
end
end
raise CRError.new("try by system was not successful")
end
|