Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/quaternion_c2/units.rb,
lib/quaternion_c2/classification.rb,
lib/quaternion_c2/to_type.rb

Direct Known Subclasses

Complex, Quaternion

Instance Method Summary collapse

Instance Method Details

#complex?Boolean

Returns true.

Returns:

  • (Boolean)


22
23
24
# File 'lib/quaternion_c2/classification.rb', line 22

def complex?
	true
end

#jQuaternion

Returns the corresponding imaginary number. Not available for quaternions.

Examples:

3.j             #=> (0+0i+3j+0k)
Complex(3, 4).j #=> (0+0i+3j+4k)

Returns:

Raises:

  • (NoMethodError)

    if self is not a complex.



33
34
35
# File 'lib/quaternion_c2/units.rb', line 33

def j
	Quaternion.send(:new, 0, self)
end

#kQuaternion

Returns the corresponding imaginary number. Not available for complex numbers.

Examples:

4.k #=> (0+0i+0j+4k)

Returns:

Raises:

  • (NoMethodError)

    if self is not a real.



47
48
49
# File 'lib/quaternion_c2/units.rb', line 47

def k
	Quaternion.send(:new, 0, self.i)
end

#to_qQuaternion

Returns the value as a quaternion.

Returns:



188
189
190
# File 'lib/quaternion_c2/to_type.rb', line 188

def to_q
	Quaternion.send(:new, self, 0)
end