Class: Matrix::Scalar
- Inherits:
-
Numeric
- Object
- Numeric
- Matrix::Scalar
- Includes:
- ExceptionForMatrix, CoercionHelper
- Defined in:
- lib/matrix.rb
Overview
Private CLASS
Instance Method Summary collapse
- #*(other) ⇒ Object
- #**(other) ⇒ Object
-
#+(other) ⇒ Object
ARITHMETIC.
- #-(other) ⇒ Object
- #/(other) ⇒ Object
-
#initialize(value) ⇒ Scalar
constructor
A new instance of Scalar.
Methods included from CoercionHelper
check_int, check_range, coerce_to, coerce_to_int, coerce_to_matrix
Constructor Details
#initialize(value) ⇒ Scalar
Returns a new instance of Scalar.
1721 1722 1723 |
# File 'lib/matrix.rb', line 1721 def initialize(value) @value = value end |
Instance Method Details
#*(other) ⇒ Object
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 |
# File 'lib/matrix.rb', line 1748 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) ⇒ Object
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 |
# File 'lib/matrix.rb', line 1772 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) ⇒ Object
ARITHMETIC
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 |
# File 'lib/matrix.rb', line 1726 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) ⇒ Object
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 |
# File 'lib/matrix.rb', line 1737 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) ⇒ Object
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 |
# File 'lib/matrix.rb', line 1759 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 |