I am trying to log the average running time of 10 threads by using the inject method but it\'s giving me this error:
undefined method `+\' for #
You need to provide an initial value for inject
in this case, since if you don't, the initial value is simply the first element in the array:
puts threads.inject(0) { |sum, e| sum + e.value}.to_f / threads.size
You didn't provide an initial value for sum in
threads.inject() { |sum, e| sum + e.value}.to_f / threads.size
Fix it with
threads.inject(0) { |sum, e| sum + e.value}.to_f / threads.size