Class: Arithmetic::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/arithmetic/expression.rb

Instance Method Summary collapse

Constructor Details

#initialize(expression) ⇒ Expression

Returns a new instance of Expression.



3
4
5
# File 'lib/arithmetic/expression.rb', line 3

def initialize(expression)
  @parsed_expression = expression
end

Instance Method Details

#evalObject



7
8
9
# File 'lib/arithmetic/expression.rb', line 7

def eval
  @result ||= @parsed_expression.eval
end

#to_s(visitor = identity_function) ⇒ Object



11
12
13
# File 'lib/arithmetic/expression.rb', line 11

def to_s(visitor=identity_function)
  @string ||= @parsed_expression.to_s(visitor)
end