Class: Numeric

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#foorth_embedObject

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

  • An embeddable form of this number as a string.



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

def foorth_embed
  self.to_s
end

#to_foorth_cObject

Convert this number to a single character string.



13
14
15
16
17
18
19
20
21
# File 'lib/fOOrth/monkey_patch/numeric.rb', line 13

def to_foorth_c
  as_int = Integer.foorth_coerce(self)

  if as_int < 0 || as_int > 1_114_111
    error "F40: Can't convert #{self} to a character."
  else
    [as_int].pack('U')
  end
end

#to_foorth_nObject

Convert this numeric to a numeric. Return self.



24
25
26
# File 'lib/fOOrth/monkey_patch/numeric.rb', line 24

def to_foorth_n
  self
end

#to_foorth_rObject

Convert this numeric to a rational.



29
30
31
# File 'lib/fOOrth/monkey_patch/numeric.rb', line 29

def to_foorth_r
  self.rationalize
end