title: Execute a dynamic method using eval or public_send
body: <p>I have these code that executes a dynamic method. I'm using <code>eval</code> here to execute it but what I wanted to do is changed it to <code>public_send</code> because I was told so and it's much safer.</p>
  <p>Current code:</p>
  <pre><code>  # update workstep logic here.
          incoming_status = params[params[:name]]
  
          # grab workflow, this is current data, use this to compare status to in comming status
          workflow = get_workorder_product_workstep(params[:workflow_id])
  
          # check current status if its pending allow to update
          # security concern EVAL!
         
          if eval(&quot;workflow.can_#{incoming_status}?&quot;)
            # update status
            eval(&quot;workflow.#{incoming_status}&quot;)
            # updated attribute handled_by
            workflow.update_attributes(handled_by_id: @curr_user.id)
            workflow.save
          else
            flash[:notice] = 'Action not allowed'
          end
  </code></pre>
  <p>The <code>eval</code> here is the concern. How can I changed this to <code>public_send</code>?</p>
  <p>Here's what I did.</p>
  <p><code>public_send(&quot;workflow.can_#{incoming_status}?&quot;)</code></p>
  <p><code>public_send(&quot;#{workflow}.can_#{incoming_status}?&quot;)</code></p>
  <p>both of them doesn't work. gives me an error of no method. The first public error returns this <code>undefined method workflow.can_queue? for #&lt;Spree::Admin::WorkordersController:0x00007ff71c8e6f00&gt;</code></p>
  <p>But it should work because I have a method <code>workflow.can_queue?</code></p>
  <p>the second error on  public is this
  <code>undefined method #&lt;Spree::WorkorderProductWorkstep:0x00007ff765663550&gt;.can_queue? for #&lt;Spree::Admin::WorkordersController:0x00007ff76597f798&gt;</code></p>
  <p>I think for the second <code>workflow</code> is being evaluated separately? I'm not sure.</p>