Method: Joules.power_v5

Defined in:
lib/joules/electricity.rb

.power_v5(voltage, resistance) ⇒ Float

Note:

There are four other methods for calculating power.

Calculates the power given voltage and resistance.

Examples:

Joules.power_v5(1.8, 3) #=> 1.08

Parameters:

  • voltage (Int, Float)

    voltage is in volts

  • resistance (Int, Float)

    resistance != 0; resistance is in ohms

Returns:

  • (Float)

    return value is in watts

Raises:

  • (ZeroDivisionError)

    if resistance = 0



298
299
300
301
302
303
304
# File 'lib/joules/electricity.rb', line 298

def power_v5(voltage, resistance)
  if resistance.zero?
    raise ZeroDivisionError.new('divided by 0')
  else
    return (voltage ** 2.0) / resistance
  end
end