Method: Joules.avg_speed

Defined in:
lib/joules/kinematics.rb

.avg_speed(distance, time) ⇒ Float

Calculates the average speed given distance and time.

Examples:

Joules.avg_speed(30, 2.4) #=> 12.5

Parameters:

  • distance (Int, Float)

    distance >= 0; distance is in metres

  • time (Int, Float)

    time > 0; time is in seconds

Returns:

  • (Float)

    return value >= 0; return value is in metres per second

Raises:

  • (ZeroDivisionError)

    if time = 0



26
27
28
29
30
31
32
# File 'lib/joules/kinematics.rb', line 26

def avg_speed(distance, time)
  if time.zero?
    raise ZeroDivisionError.new('divided by 0')
  else
    return distance / time.to_f
  end
end