Class: Complex

Inherits:
Object show all
Defined in:
lib/fOOrth/monkey_patch/complex.rb

Overview

Extensions to the Complex class required by the fOOrth language system.

Instance Method Summary collapse

Instance Method Details

#foorth_coerce(arg) ⇒ Object

Coerce the argument to match my type.



15
16
17
18
19
# File 'lib/fOOrth/monkey_patch/complex.rb', line 15

def foorth_coerce(arg)
  Complex(arg)
rescue
  error "F40: Cannot coerce a #{arg.foorth_name} to a Complex"
end

#foorth_embedObject

Convert this complex number to a form suitable for embedding in a source string.
Returns

  • An embeddable form of this complex number as a string.



8
9
10
# File 'lib/fOOrth/monkey_patch/complex.rb', line 8

def foorth_embed
  "Complex(#{self.real.foorth_embed},#{self.imaginary.foorth_embed})"
end

#to_foorth_cObject

Cannot convert this number to a single character string.



22
23
24
# File 'lib/fOOrth/monkey_patch/complex.rb', line 22

def to_foorth_c
  error "F40: Cannot convert a Complex instance to a character"
end

#to_foorth_rObject

Cannot convert this number to a Rational.



27
28
29
# File 'lib/fOOrth/monkey_patch/complex.rb', line 27

def to_foorth_r
  nil
end