Class: Resistor::CombinedResistor
- Inherits:
-
Object
- Object
- Resistor::CombinedResistor
- Defined in:
- lib/resistor/combined_resistor.rb
Instance Attribute Summary collapse
-
#ohm ⇒ Object
readonly
Returns the value of attribute ohm.
Instance Method Summary collapse
-
#+(other) ⇒ Resistor::CombinedResistor
(also: #-)
Calculates a series combined resistance value.
-
#/(other) ⇒ Resistor::CombinedResistor
(also: #|)
Calculates a parallel combined resistance value.
-
#initialize(ohm) ⇒ Resistor::CombinedResistor
constructor
Initializes a new CombinedResistor object.
Constructor Details
#initialize(ohm) ⇒ Resistor::CombinedResistor
Initializes a new CombinedResistor object.
12 13 14 |
# File 'lib/resistor/combined_resistor.rb', line 12 def initialize(ohm) @ohm = ohm.to_f end |
Instance Attribute Details
#ohm ⇒ Object (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 |