app/expression_tree.rb
def calculate(node = self.tree)

        # base case when a leaf is reached (number) 
        return ExpressionTree.process_number(node.value) if node.left.nil? && node.right.nil?

        left = Number.new(0)
        if node.left
            left = calculate(node.left)
        end

        right = Number.new(0)
        if node.left
            right = calculate(node.right)
        end

        # using send to pass the actual operator and evaluate ir using overloading of operators
        return left.send(node.value,right)   
    end
# given an expression tree root, gets the actual result
given an expression tree root, gets the actual result
given an expression tree root gets the actual result
def calculate(node = self.tree)
        return ExpressionTree.process_number(node.value) if node.left.nil? && node.right.nil?
        left = Number.new(0)
        if node.left
            left = calculate(node.left)
        end
        right = Number.new(0)
        if node.left
            right = calculate(node.right)
        end
        return left.send(node.value,right)   
    end
def calculate ( node = self . tree ) return ExpressionTree . process_number ( node . value ) if node . left . nil? && node . right . nil? left = Number . new ( 0 ) if node . left left = calculate ( node . left ) end right = Number . new ( 0 ) if node . left right = calculate ( node . right ) end return left . send ( node . value , right ) end
given an expression tree root, gets the actual result
given an expression tree root gets the actual result
# base case when a leaf is reached (number)  # using send to pass the actual operator and evaluate ir using overloading of operators
node
tree