Class: Symbolic::Coerced
- Inherits:
-
Object
- Object
- Symbolic::Coerced
- Defined in:
- lib/symbolic/coerced.rb
Overview
This class restores a correct order of arguments after using a coerce method.
For example, expression "1 - symbolic" calls to Symbolic#coerce
which gives us a power to reverse a receiver and parameter of method
so we set a receiver as Coerced.new(symbolic) to reverse arguments back after coercing.
Instance Method Summary collapse
- #*(numeric) ⇒ Object
- #**(numeric) ⇒ Object
- #+(numeric) ⇒ Object
- #-(numeric) ⇒ Object
- #/(numeric) ⇒ Object
-
#initialize(symbolic) ⇒ Coerced
constructor
A new instance of Coerced.
Constructor Details
#initialize(symbolic) ⇒ Coerced
Returns a new instance of Coerced.
9 10 11 |
# File 'lib/symbolic/coerced.rb', line 9 def initialize(symbolic) @symbolic = symbolic end |
Instance Method Details
#*(numeric) ⇒ Object
21 22 23 |
# File 'lib/symbolic/coerced.rb', line 21 def *(numeric) Factors.add numeric, @symbolic end |
#**(numeric) ⇒ Object
29 30 31 |
# File 'lib/symbolic/coerced.rb', line 29 def **(numeric) Factors.power numeric, @symbolic end |
#+(numeric) ⇒ Object
13 14 15 |
# File 'lib/symbolic/coerced.rb', line 13 def +(numeric) Summands.add numeric, @symbolic end |