Class: Resistor::CombinedResistor

Inherits:
Object
  • Object
show all
Defined in:
lib/resistor/combined_resistor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ohm) ⇒ Resistor::CombinedResistor

Initializes a new CombinedResistor object.

Parameters:

  • ohm (Float)

    resistance value

See Also:



12
13
14
# File 'lib/resistor/combined_resistor.rb', line 12

def initialize(ohm)
  @ohm = ohm.to_f
end

Instance Attribute Details

#ohmObject (readonly)

Returns the value of attribute ohm.



4
5
6
# File 'lib/resistor/combined_resistor.rb', line 4

def ohm
  @ohm
end

Instance Method Details

#+(other) ⇒ Resistor::CombinedResistor Also known as: -

Calculates a series combined resistance value.



20
21
22
# File 'lib/resistor/combined_resistor.rb', line 20

def +(other)
  Resistor::CombinedResistor.new(@ohm + other.ohm)
end

#/(other) ⇒ Resistor::CombinedResistor Also known as: |

Calculates a parallel combined resistance value.



29
30
31
# File 'lib/resistor/combined_resistor.rb', line 29

def /(other)
  Resistor::CombinedResistor.new(1 / (1 / @ohm + 1 / other.ohm))
end