class Calcula::Exprs::RatExpr

Expression for representing fractions

@author Paul T.

Public Class Methods

new(top, bot) click to toggle source

@param top [Calcula::Token] The token should have the type of NUM @param bot [Calcula::Token] The token should have the type of NUM

# File lib/Exprs/RatExpr.rb, line 10
def initialize(top, bot)
  @top = top
  @bot = bot
end

Public Instance Methods

children() click to toggle source

@see Calcula::Expr#children @param (see Calcula::Expr#children) @return (see Calcula::Expr#children)

# File lib/Exprs/RatExpr.rb, line 34
def children
  []
end
to_s(form: :src) click to toggle source

@see Calcula::Expr#to_s @param (see Calcula::Expr#to_s) @return (see Calcula::Expr#to_s)

# File lib/Exprs/RatExpr.rb, line 18
def to_s(form: :src)
  case form
  when :src then
    "#{@top.text}//#{@bot.text}"
  when :tree then
    "(rat #{@top.text} #{@bot.text})"
  when :ruby then
    "Rational(#{@top.text}, #{@bot.text})"
  else
    nil
  end
end