title: Ruby RPN Calculator - rspec test
body: <p>Can someone help me understand the below answer? I know it's the correct answer to make the following rspec test pass. Also is there a different/simpler way to implement this? As I don't understand how it does it. </p>
  
  <pre><code> def tokens(string)
      string.split.map{|s| s[/\d/] ? s.to_i : s.to_sym}
   end
  
   def evaluate(pol)
          order = []
          opps = {:+ =&gt; plus, :- =&gt; minus, :/ =&gt; divide, :* =&gt; times }
          tokens(pol).reverse.chunk{|n| n.is_a?(Integer)}.each{|e,a| e == true ? a.reverse.each{|a| push(a) } : a.each {|a| order.push(a) }}
          order.reverse.each {|o| (opps[o]) }   end
  </code></pre>
  
  <p>rspec test:</p>
  
  <pre><code># extra credit
    it "tokenizes a string" do
      calculator.tokens("1 2 3 * + 4 5 - /").should ==
        [1, 2, 3, :*, :+, 4, 5, :-, :/]
    end
  
    # extra credit
    it "evaluates a string" do
      calculator.evaluate("1 2 3 * +").should ==
        ((2 * 3) + 1)
  
      calculator.evaluate("4 5 -").should ==
        (4 - 5)
  
      calculator.evaluate("2 3 /").should ==
        (2.0 / 3.0)
  
      calculator.evaluate("1 2 3 * + 4 5 - /").should ==
        (1.0 + (2 * 3)) / (4 - 5)
    end
  </code></pre>