Class: Rational
Overview
Extensions to the Rational class required by the fOOrth language system.
Class Method Summary collapse
-
.foorth_coerce(arg) ⇒ Object
Coerce the argument to match my type.
Instance Method Summary collapse
-
#foorth_coerce(arg) ⇒ Object
Coerce the argument to match my type.
-
#foorth_embed ⇒ Object
Convert this rational number to a form suitable for embedding in a source string.
-
#to_foorth_r ⇒ Object
Convert this object to a rational.
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_embed ⇒ Object
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 "'#{self.to_s}'.to_r" end |
#to_foorth_r ⇒ Object
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 |