class Variable

This is the class for a variable in an expression. It is part of the CAS side-project in ChebyRuby.

@attr x [String] the variable name @attr neg [Boolean] the negation status of the variable

Attributes

neg[RW]
x[RW]

Public Class Methods

new(x, neg = false) click to toggle source

This is the constructor for the variable class

@param [String] x the variable name to initialize @param [Boolean] neg the negation status of the variable

# File lib/chebyruby/variable.rb, line 15
def initialize(x, neg = false)
  @x = x
  @neg = false
end

Public Instance Methods

-@() click to toggle source

This is an overriding of the unary negation operation that allows for negation of a variable as simply as -x.

@return a negated form of the current variable

# File lib/chebyruby/variable.rb, line 45
def -@
  Variable.new(@x, !@neg)
end
method_missing(method, *args) click to toggle source

This variadic method missing works with Expression's method missing to construct and expression from variables.

@param [Object] method the method that is missing @param [Object args the args that are passed to the missing method @return a new expression

# File lib/chebyruby/variable.rb, line 26
def method_missing(method, *args)
  Expression.new(self, method, Variable.new(args[0]))
end
parseable() click to toggle source

Returns a parseable version of the variable/expression for computer system modification.

@return parseable form

# File lib/chebyruby/variable.rb, line 74
def parseable
  to_enum.map do |i|
    if Array === i
      i.parseable
    elsif Symbol === i
      i
    else
      i.x
    end
  end
end
right() click to toggle source

A nil returning function for the purposes of expression building

@return nil

# File lib/chebyruby/variable.rb, line 59
def right
  nil
end
to_a() click to toggle source

This method will turn a variadic variable into an array

@return an array of the variable

# File lib/chebyruby/variable.rb, line 33
def to_a
  if x.class == Array
    x
  else
    [x]
  end
end
Also aliased as: to_ary
to_ary()
Alias for: to_a
to_enum() click to toggle source

This turns the current array variable into an enumerator

@return an enumerated form of the array variable

# File lib/chebyruby/variable.rb, line 52
def to_enum
  Array.new(to_ary).to_enum
end
to_s() click to toggle source

A basic to_s function

@return a string

# File lib/chebyruby/variable.rb, line 66
def to_s
  "#{x}"
end