Class: FastMatrix::Scalar
- Inherits:
-
Numeric
- Object
- Numeric
- FastMatrix::Scalar
- Defined in:
- lib/scalar.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #**(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #==(other) ⇒ Object
- #coerce(other) ⇒ Object
-
#initialize(value) ⇒ Scalar
constructor
A new instance of Scalar.
Constructor Details
#initialize(value) ⇒ Scalar
Returns a new instance of Scalar.
45 46 47 |
# File 'lib/scalar.rb', line 45 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
43 44 45 |
# File 'lib/scalar.rb', line 43 def value @value end |
Instance Method Details
#*(other) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/scalar.rb', line 67 def *(other) case other when Vector, Matrix other * @value else Scalar.new(@value * other) end end |
#**(other) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/scalar.rb', line 87 def **(other) case other when Vector, Matrix raise OperationNotDefinedError, "#{@value.class}**#{other.class}" else Scalar.new(@value**other) end end |
#+(other) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/scalar.rb', line 49 def +(other) case other when Vector, Matrix raise OperationNotDefinedError, "#{@value.class}+#{other.class}" else Scalar.new(@value + other) end end |
#-(other) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/scalar.rb', line 58 def -(other) case other when Vector, Matrix raise OperationNotDefinedError, "#{@value.class}+#{other.class}" else Scalar.new(@value - other) end end |
#/(other) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/scalar.rb', line 76 def /(other) case other when Vector raise OperationNotDefinedError, "#{@value.class}/#{other.class}" when Matrix self * other.inverse else Scalar.new(@value / other) end end |
#==(other) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/scalar.rb', line 96 def ==(other) case other when Scalar other.value == @value else @value == other end end |
#coerce(other) ⇒ Object
105 106 107 |
# File 'lib/scalar.rb', line 105 def coerce(other) @value.coerce(other) end |