title: How to check if a variable exists with a value without "undefined local variable or method"?
body: <p>This is a common pattern: If a variable doesn't exist I get an <code>undefined local variable or method</code> error.</p>
  
  <p>The existing code has <code>if variable_name.present?</code> but this didn't account for the variable not existing.</p>
  
  <p>How can I check the value of the variable and also account for it not existing at all?</p>
  
  <p>I've tried:</p>
  
  <pre><code>if (defined? mmm) then
    if mmm.present? then
      puts "true"
    end
  end
  </code></pre>
  
  <p>but Ruby still checks that inner <code>mmm.present?</code> and throws "no such variable" when it doesn't exist.</p>
  
  <p>I'm sure there's a common pattern/solution to this.</p>