Sha256: ef478a6c7003df0446c0bc21e375358a13949e774f541a0c4819740e02febd0a
Contents?: true
Size: 612 Bytes
Versions: 5
Compression:
Stored size: 612 Bytes
Contents
class HpSqrt < Numeric class Term attr_reader :number attr_reader :sqrt def initialize(number: 1, sqrt: 1) @number = number @sqrt = sqrt freeze end def *(other) if self.class===other n = @number * other.number s = 1 if @sqrt==other.sqrt n *= @sqrt else s = @sqrt * other.sqrt end self.class.new(number: n, sqrt: s) end end def eql?(other) self.class===other && @number==other.number && @sqrt==other.sqrt end def hash [@number, @sqrt].hash end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
hpsqrt-1.6.0 | lib/hpsqrt/term.rb |
hpsqrt-1.5.0 | lib/hpsqrt/term.rb |
hpsqrt-1.4.0 | lib/hpsqrt/term.rb |
hpsqrt-1.3.0 | lib/hpsqrt/term.rb |
hpsqrt-1.2.0 | lib/hpsqrt/term.rb |