title: Ruby on Rails Meta Programming - Defining a class method using a dynamic array
body: <p>I'm trying to use the meta programming example code in RailsCast #345 (Hstore) and replace the static array with one generated from another (unrelated) Model in the application.  The code sample from Ryan is:</p>
  
  <pre><code>class Product &lt; ActiveRecord::Base
    attr_accessible :name, :category, :price, :description
  
    # store_accessor :properties, :author
  
    %w[author rating runtime].each do |key|
      attr_accessible key
  
      define_method(key) do
        properties &amp;&amp; properties[key]
      end
  
      define_method("#{key}=") do |value|
        self.properties = (properties || {}).merge(key =&gt; value)
      end
    end
  end
  </code></pre>
  
  <p>I would like to replace <code>%w[author rating runtime]</code> above with something like <code>Foo.pluck(:content).map(&amp;:downcase)</code> but that doesn't work.  I get a method undefined error when I try to access the dynamic methods. For example when calling </p>
  
  <pre><code>@product.send(foo.content.downcase) # &lt;-- which returns "author"
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>undefined method `author' for #&lt;Product:0x007ff111df0908&gt;
  </code></pre>
  
  <p>It works fine using the static array.</p>
  
  <p>Is it possible to replace that static array? I'd like to read those values from another model that an administrator populates and not have to touch the code for new values.  Open to alternative ways to accomplish the same thing too! Thanks for your time.</p>