Class: Symbolic::Coerced

Inherits:
Object
  • Object
show all
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

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

#-(numeric) ⇒ Object


17
18
19
# File 'lib/symbolic/coerced.rb', line 17

def -(numeric)
  Summands.subtract numeric, @symbolic
end

#/(numeric) ⇒ Object


25
26
27
# File 'lib/symbolic/coerced.rb', line 25

def /(numeric)
  Factors.subtract numeric, @symbolic
end