Error when using eval to execute aasm block <p>We put the whole <code>aasm</code> block in string and eval it in <code>payment_request</code> model. Here is the def:</p> <pre><code>class PaymentRequest &lt; :ActiveRecord::Base include AASM def self.load_wf_spec(wf_spec, wf_def_name) eval("aasm(:#{wf_def_name}) :column =&gt; 'wf_state' {#{wf_spec}}") end end </code></pre> <p>The error is:</p> <pre><code> Failure/Error: eval("aasm(:#{wf_def_name}) :column =&gt; 'wf_state' {#{wf_spec}}") SyntaxError: (eval):1: syntax error, unexpected ':', expecting end-of-input aasm(:test) :column =&gt; 'wf_state' {state :... ^ # ./app/models/payment_requestx/payment_request.rb:11:in `eval' </code></pre> <p>Here is the value of the variable:</p> <pre><code> wf_def_name = 'test' wf_spec = "state :initial_state, :initial =&gt; true state :ceo_reviewing state :approved state :stamped state :paid state :rejected event :submit_test do transitions :from =&gt; :initial_state, :to =&gt; :ceo_reviewing end event :ceo_approve_test do transitions :from =&gt; :ceo_reviewing, :to =&gt; :approved end event :ceo_reject_test do transitions :from =&gt; :ceo_reviewing, :to =&gt; :rejected end event :ceo_rewind_test do transitions :from =&gt; :ceo_reviewing, :to =&gt; :initial_state end event :stamp_test do transitions :from =&gt; :approved, :to =&gt; :stamped end event :pay_test do transitions :from =&gt; :stamped, :to =&gt; :paid end" </code></pre> <p>If removing (:test)', then the same error points to next:</p> <pre><code>Failure/Error: eval("aasm :column =&gt; 'wf_state' {#{wf_spec}}") SyntaxError: (eval):1: syntax error, unexpected '{', expecting end-of-input aasm :column =&gt; 'wf_state' {state :initial_state, :initial =&gt; true ^ # ./app/models/payment_requestx/payment_request.rb:11:in `eval' </code></pre> <p>What is missing in the eval? Thanks.</p>