class Crapshoot::Tokens::Arithmetic
Public Class Methods
new(operation)
click to toggle source
# File lib/crapshoot/tokens/arithmetic.rb, line 4 def initialize(operation) @operation = operation end
Public Instance Methods
eval(stack)
click to toggle source
# File lib/crapshoot/tokens/arithmetic.rb, line 21 def eval(stack) r = stack.pop l = stack.pop @result = Result.new l.send(@operation.to_sym, r) @result.description = "#{l.description}#{@operation}#{r.description}" @result.detailed_description = l.detailed_description + [[@operation, @operation]] + r.detailed_description return @result end
high_priority?()
click to toggle source
# File lib/crapshoot/tokens/arithmetic.rb, line 17 def high_priority? @operation == '*' || @operation == '/' end
independent()
click to toggle source
# File lib/crapshoot/tokens/arithmetic.rb, line 8 def independent false end
inspect()
click to toggle source
# File lib/crapshoot/tokens/arithmetic.rb, line 30 def inspect "<Crapshoot::Tokens::Arithmetic operation=#{@operation}>" end
precedent(stack_top)
click to toggle source
# File lib/crapshoot/tokens/arithmetic.rb, line 12 def precedent(stack_top) return true if high_priority? && !stack_top.high_priority? return false end