title: Ruby coding exercise solution (rubymonk)
body: <p>I am working on understanding a Rubymonk coding exercise solution, and am having trouble understanding what is going on in the <code>cost</code> method.</p>
  
  <p>For reference, the <code>menu</code> is <code>{:rice =&gt; 3, :noodles =&gt; 2}</code> and the purpose of this is to calculate the total cost of orders from the <code>menu</code>.</p>
  
  <p>An order example would be:</p>
  
  <pre><code>{:rice =&gt; 1, :noodles =&gt; 1} )
  </code></pre>
  
  <p>The solution I came up with was simpler, at least in my head, but returned a "cannot convert Symbol to an Integer" error which I was unable to rectify through <code>to_i</code>.</p>
  
  <pre><code>    class Restaurant
    def initialize(menu)
      @menu = menu
    end
  
    def cost(*orders)
      orders.inject(0) do |total_cost, order|
        total_cost + order.keys.inject(0) {|cost, key| cost + @menu[key]*order[key] }
      end
    end
  end
  </code></pre>
  
  <p>Can someone please explain each step in the <code>cost</code> method simply?</p>