title: ERB template nested variable - accessing a hash key based on array element
body: <p>I have the following data and erb template: a hash mapping services to port numbers and an array of services.</p>
  
  <p>I iterate over the array for each service and I need to access the hash to get the port number for the currently being processed service. I don't seem to be allowed to nest variables the way I am doing below. Is there a better way?</p>
  
  <pre><code>ports = {"max-api" =&gt; 83, "max-logger" =&gt; 82, "max-data" =&gt; 84}
  
  services = %w( max_api max_data max_logger )
  
    &lt;% @services.each do |service| %&gt;
        &lt;% if service.include?("max_logger") %&gt;
          shell: echo &lt;%= service %&gt;:&lt;%= @ports["&lt;%= service %&gt;"] %&gt;
        &lt;% else %&gt;
          shell: echo &lt;%= service %&gt;:&lt;%= @ports["&lt;%= service %&gt;"] %&gt;00  
        &lt;% end %&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>Simplest possible example I have the erb template</p>
  
  <pre><code>&lt;% @services.each do |service| %&gt;
  &lt;%= @ports[&lt;%= service %&gt;] %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>If I try to run my code I get the following error:</p>
  
  <pre><code>Chef::Mixin::Template::TemplateError
  ------------------------------------
  (erubis):2: syntax error, unexpected '&lt;', expecting ']'
   _buf &lt;&lt; ( @ports[&lt;%= service ).to_s; _buf &lt;&lt; ']...
                     ^
  (erubis):2: unterminated string meets end of file
  </code></pre>