Class: Veritas::Function::Numeric::SquareRoot

Inherits:
Veritas::Function::Numeric show all
Includes:
Unary::Invertible, Unary
Defined in:
lib/veritas/function/numeric/square_root.rb

Overview

A class representing a square root function

Defined Under Namespace

Modules: Methods

Instance Attribute Summary

Attributes included from Operation::Unary

#operand

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Unary

#==, #call, #rename

Methods included from Comparator

#compare

Methods included from Unary::Callable

#call, #included

Methods included from Operation::Unary

#initialize

Methods included from Immutable

#dup, #freeze, included, #memoize, #memoized

Methods included from AbstractClass

included

Methods inherited from Veritas::Function

extract_value, #rename, rename_attributes

Methods included from Visitable

#accept

Class Method Details

.call(value) ⇒ Numeric

Return the square root of the value

Examples:

square_root = SquareRoot.call(value)

Parameters:

Returns:



21
22
23
# File 'lib/veritas/function/numeric/square_root.rb', line 21

def self.call(value)
  Math.sqrt(value)
end

Instance Method Details

#inspectString

Return a string representing the square root function

Examples:

square_root.inspect  # => "SQRT(4)"

Returns:



55
56
57
# File 'lib/veritas/function/numeric/square_root.rb', line 55

def inspect
  "SQRT(#{operand.inspect})"
end

#inverseExponentiation

Return the inverse function

Examples:

inverse = square_root.inverse

Returns:



33
34
35
36
# File 'lib/veritas/function/numeric/square_root.rb', line 33

def inverse
  Exponentiation.new(operand, 2).
    memoize(:inverse, self)
end

#typeClass<Attribute::Float>

Return the type returned from #call

Returns:



43
44
45
# File 'lib/veritas/function/numeric/square_root.rb', line 43

def type
  Attribute::Float
end