Module: Electr::EvalFunction

Defined in:
lib/electr/repl/eval_function.rb

Class Method Summary collapse

Class Method Details

.eval(function_name, stack) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/electr/repl/eval_function.rb', line 5

def self.eval(function_name, stack)
  case function_name
  when "sqrt", ""
    a = stack.pop
    stack.push(Math::sqrt(a))
  when "sin"
    a = stack.pop
    stack.push(Math::sin(a))
  when "cos"
    a = stack.pop
    stack.push(Math::cos(a))
  when "tan"
    a = stack.pop
    stack.push(Math::tan(a))
  end
end