class Array

Provide some helpers for array math These will only work on arrays of number values

Public Instance Methods

average() click to toggle source

Get the average value for an array

# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 10
def average
  inject(&:+) / length
end
divide(arr) click to toggle source

Perform division

  • If provided with an array, will divide all values

  • If provided with an integer, will divide all values by that value

# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 17
def divide(arr)
  do_math(arr) do |a,b|
    a.to_f / b
  end
end
mult(arr) click to toggle source

Perform multiplication

  • If provided with an array, will multiply all values

  • If provided with an integer, will multiply all values by that value

# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 26
def mult(arr)
  do_math(arr) do |a,b|
    a * b
  end
end

Protected Instance Methods

do_math(arr) { |first,last| ... } click to toggle source
# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 33
def do_math(arr)
  unless arr.is_a?(Array)
    arr = [arr] * length
  end
  zip(arr).map{|x| yield x.first,x.last }
end