class Rational

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

Public Class Methods

foorth_coerce(arg) click to toggle source

Coerce the argument to match my type.

# File lib/fOOrth/monkey_patch/rational.rb, line 20
def self.foorth_coerce(arg)
  arg.to_foorth_r || (error "F40: Cannot coerce a #{arg.foorth_name} to a Rational")
end

Public Instance Methods

foorth_coerce(arg) click to toggle source

Coerce the argument to match my type.
Endemic Code Smells

  • :reek:FeatureEnvy – false positive

# File lib/fOOrth/monkey_patch/rational.rb, line 27
def foorth_coerce(arg)
  arg.to_foorth_r || (error "F40: Cannot coerce a #{arg.foorth_name} to a Rational")
end
foorth_embed() click to toggle source

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

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

# File lib/fOOrth/monkey_patch/rational.rb, line 8
def foorth_embed
  "'#{self.to_s}'.to_r"
end
to_foorth_r() click to toggle source

Convert this object to a rational. Returns self.

# File lib/fOOrth/monkey_patch/rational.rb, line 13
def to_foorth_r
  self
end