Class: Obfuscator::SquareRoot

Inherits:
Expression show all
Defined in:
lib/number_obfuscator/square_root.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

addType, makeExpression

Constructor Details

#initialize(square) ⇒ SquareRoot

Returns a new instance of SquareRoot


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

def initialize(square)
  @square = square
end

Class Method Details

.canDo(n) ⇒ Object


20
21
22
# File 'lib/number_obfuscator/square_root.rb', line 20

def SquareRoot.canDo(n)
  n > 1
end

.make(n, depth) ⇒ Object


24
25
26
27
# File 'lib/number_obfuscator/square_root.rb', line 24

def SquareRoot.make(n, depth)
  s = n * n
  SquareRoot.new(makeExpression(s, depth - 1))
end

Instance Method Details

#to_sObject


12
13
14
# File 'lib/number_obfuscator/square_root.rb', line 12

def to_s
  "Math.sqrt(#{@square.to_s})"
end

#to_texObject


16
17
18
# File 'lib/number_obfuscator/square_root.rb', line 16

def to_tex
  "\\sqrt{#{@square.to_tex}}"
end