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
Public Class Methods
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
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
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
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
A nil returning function for the purposes of expression building
@return nil
# File lib/chebyruby/variable.rb, line 59 def right nil end
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
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
A basic to_s
function
@return a string
# File lib/chebyruby/variable.rb, line 66 def to_s "#{x}" end