title: ruby dynamic chaining methods
body: <p>HI</p>
  
  <p>I try to build some dynamic defined methods and chain some scope methods something like:</p>
  
  <pre><code>define_method "#{instance_name_method}" do
          Kernel.const_get(model_name).___some_chaining methods basd on condition
  end
  </code></pre>
  
  <p>One idea for that is something like:</p>
  
  <pre><code>method_action = model_name #ex Post
  
  ['latest', 'old', 'deleted','latest_deleted','archived'].each do |prefix| 
  
    method_action &lt;&lt; ".deleted"  if prefix.match('deleted') 
    method_action &lt;&lt; ".latest"  if prefix.match('latest')
    method_action &lt;&lt; ".old"  if prefix.match('old')
  
    define_method "#{prefix}_#{instance_name_method}" do
             eval( method_action)
      end
  
  
  end
  </code></pre>
  
  <p>in post we have defiend scopes latest,old ...</p>
  
  <p>Now we can call  methods like:</p>
  
  <pre><code>Post.latest or Post.old_archived etc...
  </code></pre>
  
  <p>My questions are:   </p>
  
  <ol>
  <li><p>Is there a better approach for doing this? (similar to active record find but without method_missing) this is kind ugly...</p></li>
  <li><p>How can I chain methods dynamically ?</p></li>
  </ol>
  
  <p>I already know for send('method',var)  but i don't know how to join those methods from strings based on condition...</p>
  
  <p>Thanks</p>