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.
1784 1785 1786 |
# File 'lib/matrix.rb', line 1784 def initialize(value) @value = value end |
Instance Method Details
#*(other) ⇒ Object
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 |
# File 'lib/matrix.rb', line 1811 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
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 |
# File 'lib/matrix.rb', line 1835 def **(other) case other when Numeric Scalar.new(@value ** other) when Vector raise ErrOperationNotDefined, ["**", @value.class, other.class] when Matrix #other.powered_by(self) raise ErrOperationNotImplemented, ["**", @value.class, other.class] else apply_through_coercion(other, __method__) end end |
#+(other) ⇒ Object
ARITHMETIC
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 |
# File 'lib/matrix.rb', line 1789 def +(other) case other when Numeric Scalar.new(@value + other) when Vector, Matrix raise ErrOperationNotDefined, ["+", @value.class, other.class] else apply_through_coercion(other, __method__) end end |
#-(other) ⇒ Object
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 |
# File 'lib/matrix.rb', line 1800 def -(other) case other when Numeric Scalar.new(@value - other) when Vector, Matrix raise ErrOperationNotDefined, ["-", @value.class, other.class] else apply_through_coercion(other, __method__) end end |
#/(other) ⇒ Object
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 |
# File 'lib/matrix.rb', line 1822 def /(other) case other when Numeric Scalar.new(@value / other) when Vector raise ErrOperationNotDefined, ["/", @value.class, other.class] when Matrix self * other.inverse else apply_through_coercion(other, __method__) end end |