class HpSqrt::Term
Attributes
number[R]
sqrt[R]
Public Class Methods
new(number: 1, sqrt: 1)
click to toggle source
# File lib/hpsqrt/term.rb, line 7 def initialize(number: 1, sqrt: 1) unless Numeric===number raise TypeError, "can't convert %s into %s: %s" % [number.class.name, self.class.name, number.inspect] end unless Numeric===sqrt raise TypeError, "can't convert %s into %s: %s" % [sqrt.class.name, self.class.name, sqrt.inspect] end @number = number @sqrt = sqrt freeze end
Public Instance Methods
*(other)
click to toggle source
# File lib/hpsqrt/term.rb, line 20 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
eql?(other)
click to toggle source
# File lib/hpsqrt/term.rb, line 34 def eql?(other) self.class===other && @number==other.number && @sqrt==other.sqrt end
hash()
click to toggle source
# File lib/hpsqrt/term.rb, line 38 def hash [@number, @sqrt].hash end