title: ruby metaprogramming alternative to eval
body: <p>I have the following statement which does work although it uses eval:</p>
  
  <pre><code>  def resource_name
      self.class.to_s.match(/(.+)Controller/)[1].singularize
    end
  
    def collection
      @collection ||= eval "#{resource_name}.all(sort: [[:name, :asc]])"
    end
  </code></pre>
  
  <p>Is there a better way of doing this that does not use eval?</p>