Sha256: fd4c3ef49cb00527eb2836853d12f8b44ac33806aae1ce7e7839033b059ce30e
Contents?: true
Size: 613 Bytes
Versions: 2
Compression:
Stored size: 613 Bytes
Contents
class HpSqrt < Numeric class Value 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hpsqrt-1.1.0 | lib/hpsqrt/value.rb |
hpsqrt-1.0.0 | lib/hpsqrt/value.rb |