title: Accessing variable name
body: <p>I trying to some parameter validation outside of Rails. </p>
  
  <pre><code>def create_statement(action, ...)
    valid_one_of(action, ['ADD', 'MOVE', 'DELETE'])
    ...
  end
  </code></pre>
  
  <p>Validation Method:</p>
  
  <pre><code>def valid_one_of(input, valid_values)
    return true if valid_values.include?(input)
    raise "#{input} was not a valid value for #{input.var_name}" 
  end
  </code></pre>
  
  <p>Sample Call:</p>
  
  <pre><code>create_statement('Bob')
  </code></pre>
  
  <p>So the output would be: <pre>Bob was not valid value for action</pre></p>
  
  <p>The problem how do i get <strong>input.var_name</strong> ?</p>
  
  <hr>
  
  <p>I for a workaround I could pass</p>
  
  <pre><code>valid_one_of(action, ['ADD', 'MOVE', 'DELETE'], 'action')
  </code></pre>
  
  <p>(and use 3rd parm for my output) but this doesn't seem feels bit redundant.  </p>
  
  <p>If its not possible to access variable name is there a more DRY coding style than this workaround?</p>