Class: Rational

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

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.foorth_coerce(arg) ⇒ Object

Coerce the argument to match my type.



20
21
22
# 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

Instance Method Details

#foorth_coerce(arg) ⇒ Object

Coerce the argument to match my type.
Endemic Code Smells

  • :reek:FeatureEnvy – false positive



27
28
29
# 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_embedObject

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.



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

def foorth_embed
  "'#{self.to_s}'.to_r"
end

#to_foorth_rObject

Convert this object to a rational. Returns self.



13
14
15
# File 'lib/fOOrth/monkey_patch/rational.rb', line 13

def to_foorth_r
  self
end