Sha256: fbe2e94dd41bbc5b0edc817c8478e80b89f4b8d0d77b53490f7f294b168c1088
Contents?: true
Size: 687 Bytes
Versions: 1
Compression:
Stored size: 687 Bytes
Contents
class Variable < Struct.new(:value) def to_s "#{value} #{self.class.to_s.downcase}s" end def inspect to_s end def and(other) current = resistance = voltage = nil [self, other].each do |element| case element when Ampere current = element.value when Ohm resistance = element.value when Volt voltage = element.value end end if current.nil? Ampere.new(voltage / resistance) elsif resistance.nil? Ohm.new(voltage / current) elsif voltage.nil? Volt.new(current * resistance) end end end class Ampere < Variable end class Ohm < Variable end class Volt < Variable end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
strom-0.0.2 | lib/strom/variable.rb |