title: Ruby on Rails - using a block parameter as a method call
body: <p>I'm having trouble with a little Ruby on Rails I'm building and need some help.
  I have a Table with 20+ Columns and a corresponding XML File which can be parsed as some sort of hash with a gem. Every key would be mapped to a column and every value would be a data record in said column.</p>
  
  <p>The way I access a specific value in the already parsed XML file is:</p>
  
  <pre><code>filename["crs","inputkeyhere"]
  </code></pre>
  
  <p>which returns the value, for example "52" or whatever.</p>
  
  <p>What I am trying to do is upload the file, parse it with the gem and give each column the corresponding value.</p>
  
  <p>My table (or model) is called "Attributeset" and I already know how I can access every column:</p>
  
  <pre><code>@attributeset = Attributeset.new    
  @attributeset.attributes.keys
  </code></pre>
  
  <p>So my thought process was:</p>
  
  <ol>
  <li>Iterate over all the keys</li>
  <li>Pass every key into a block called |a|</li>
  <li>Use the rails possibilty to set attributes by calling the corresponding @attributeset.</li>
  <li>Set colum attribute to the corresponding xml key</li>
  </ol>
  
  <p>So my code would go something like this:</p>
  
  <pre><code>@attributeset.attributes.keys.each do |a|
        @attributeset.a=filename["crs",a]
   end
  </code></pre>
  
  <p>But my problem is, that ruby thinks ".a" is a method and apparently does not evaluate "a" to the block parameter.
  I've read through lambdas and procs and whatnot but didn't really understand how they could work for my specific situation.</p>
  
  <p>Coming from bash scripting maybe my thinking might be wrong but I thought that the .a might get evaluated.
  I know I can run the block with yield, but this only works in methods as far as I know..</p>
  
  <p>Any help is appreciated.
  Thanks and stay healthy,
  Alex</p>