123456789_123456789_123456789_123456789_123456789_

Class: Matrix::Scalar

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Numeric
Instance Chain:
Inherits: Numeric
  • Object
Defined in: lib/matrix.rb

Overview

Private CLASS

Class Method Summary

Instance Method Summary

CoercionHelper - Included

#apply_through_coercion

Applies the operator oper with argument obj through coercion of obj

Constructor Details

.new(value) ⇒ Scalar

[ GitHub ]

  
# File 'lib/matrix.rb', line 1558

def initialize(value)
  @value = value
end

Instance Method Details

#*(other)

[ GitHub ]

  
# File 'lib/matrix.rb', line 1585

def *(other)
  case other
  when Numeric
    Scalar.new(@value * other)
  when Vector, Matrix
    other.collect{|e| @value * e}
  else
    apply_through_coercion(other, __method__)
  end
end

#**(other)

[ GitHub ]

  
# File 'lib/matrix.rb', line 1609

def **(other)
  case other
  when Numeric
    Scalar.new(@value ** other)
  when Vector
    Scalar.Raise ErrOperationNotDefined, "**", @value.class, other.class
  when Matrix
    #other.powered_by(self)
    Scalar.Raise ErrOperationNotImplemented, "**", @value.class, other.class
  else
    apply_through_coercion(other, __method__)
  end
end

#+(other)

ARITHMETIC

[ GitHub ]

  
# File 'lib/matrix.rb', line 1563

def +(other)
  case other
  when Numeric
    Scalar.new(@value + other)
  when Vector, Matrix
    Scalar.Raise ErrOperationNotDefined, "+", @value.class, other.class
  else
    apply_through_coercion(other, __method__)
  end
end

#-(other)

[ GitHub ]

  
# File 'lib/matrix.rb', line 1574

def -(other)
  case other
  when Numeric
    Scalar.new(@value - other)
  when Vector, Matrix
    Scalar.Raise ErrOperationNotDefined, "-", @value.class, other.class
  else
    apply_through_coercion(other, __method__)
  end
end

#/(other)

[ GitHub ]

  
# File 'lib/matrix.rb', line 1596

def /(other)
  case other
  when Numeric
    Scalar.new(@value / other)
  when Vector
    Scalar.Raise ErrOperationNotDefined, "/", @value.class, other.class
  when Matrix
    self * other.inverse
  else
    apply_through_coercion(other, __method__)
  end
end