Undefined method in eval()
<p>Eval() is used to eval a <code>workflow</code> block in Rails 4.2 model <code>payment_request</code>. Here is the <code>workflow</code> block before using <code>eval</code>:</p>

<pre><code>  class PaymentRequest &lt; ActiveRecord::Base
    include Workflow
    def self.load_wf
      workflow do
        state :initial_state do
          event :submit, :transitions_to =&gt; :ceo_reviewing
        end
        state :ceo_reviewing do
          event :reject, :transitions_to =&gt; :rejected
          event :approve, :transitions_to =&gt; :approved
        end
        state :rejected
        state :approved
      end
    end
    ..........
  end
</code></pre>

<p>String variable <code>spec</code> is defined as:</p>

<pre><code>spec = "state :initial_state do
    event :submit, :transitions_to =&gt; :ceo_reviewing
  end
  state :ceo_reviewing do
    event :reject, :transitions_to =&gt; :rejected
    event :approve, :transitions_to =&gt; :approved
  end
  state :rejected
  state :approved"
</code></pre>

<p>And rewrite:</p>

<pre><code>  class PaymentRequest &lt; ActiveRecord::Base
    include Workflow
    def self.load_wf(spec)
      eval("Workflow::ClassMethods.workflow {#{spec}}")    
    end
     ...............
  end
</code></pre>

<p>The <code>eval</code> generates error: </p>

<p><code>undefined method 'workflow' for Workflow::ClassMethods:Module.</code> </p>

<p><code>workflow</code> is a method in a gem:</p>

<pre><code>module Workflow
  module ClassMethods
    attr_reader :workflow_spec
    .....
    def workflow(&amp;specification)
      assign_workflow Specification.new(Hash.new, &amp;specification)
    end
    ......
  end
end
</code></pre>

<p>Tried to add binding in eval and it did not work (not sure if the binding is used correctly). How to make <code>eval</code> find method <code>workflow</code> &amp; execute it in the model <code>payment_request</code>?</p>