Class: Obfuscator::Subtraction

Inherits:
BinaryExpression show all
Defined in:
lib/number_obfuscator/subtraction.rb

Instance Attribute Summary

Attributes inherited from BinaryExpression

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BinaryExpression

#initialize, make

Methods inherited from Expression

addType, make, makeExpression

Constructor Details

This class inherits a constructor from Obfuscator::BinaryExpression

Class Method Details

.canDo(n) ⇒ Object


18
19
20
# File 'lib/number_obfuscator/subtraction.rb', line 18

def Subtraction.canDo(n)
  n > 0
end

.makePair(n) ⇒ Object


22
23
24
25
26
# File 'lib/number_obfuscator/subtraction.rb', line 22

def Subtraction.makePair(n)
  l = n + rand(2*n) + 3
  r = l - n
  [l, r]
end

Instance Method Details

#to_sObject


8
9
10
# File 'lib/number_obfuscator/subtraction.rb', line 8

def to_s
  "#{left.to_s}-(#{right.to_s})"
end

#to_texObject


12
13
14
15
16
# File 'lib/number_obfuscator/subtraction.rb', line 12

def to_tex
  r = right.to_tex
  r = "(#{r})" if Summation === right || Subtraction === right
  "#{left.to_tex}-#{r}"
end