Class: Nelson::SubtractionExpression

Inherits:
Expression show all
Defined in:
lib/nelson/expressions/subtraction_expression.rb

Instance Attribute Summary

Attributes inherited from Expression

#terms

Instance Method Summary collapse

Methods inherited from Expression

#*, #+, #-, #/, #has_term?, #initialize

Constructor Details

This class inherits a constructor from Nelson::Expression

Instance Method Details

#callObject



4
5
6
# File 'lib/nelson/expressions/subtraction_expression.rb', line 4

def call
  terms.reduce(:-)
end

#to_sObject



9
10
11
12
13
# File 'lib/nelson/expressions/subtraction_expression.rb', line 9

def to_s
  terms.map do |t|
    t.is_a?(Expression) ? "(#{t})" : t
  end.join("-")
end