Ruby Function call not working in Cloud9 for some reason

ruby

#1

Dear all,

I’m trying to duplicate the RPN caculator code found Here. When I run my code I get an Error: undefined method `evaluate’ for main:Object (NoMethodError)

Any suggestions? It does not seem that the author would put up faulty code on her website.

class RPNCalculator
	def evaluate(expression)
		expression = expression.split
		operands = []
		evaluation = []

		expression.each do |x|
			case x
				when /\d/
					evaluation.push(x.to_f)
				when "-", "/", "*", "+", "**"
					operands = evaluation.pop(2)
					evaluation.push(operands[0].send(x, operands[1]))
			end
		end
		puts evaluation
	end
end

input = "112++"
evaluate(input)

Thanks,
Bill


#2

The code looks faulty to me. The evalute method is a child of the RPNCalculator class, so try changing that last line to RPNCalculator.evaluate(input)