title: Lazy-evaluation of a "#{}"-string in ruby
body: <p>I started to put print-statements throughout my code. So as not to clutter up the output, I did something like:</p>
  
  <pre><code>dputs LEVEL, "string"
  </code></pre>
  
  <p>where <code>LEVEL</code> is 0 for errors, 1 for important .. 5 for verbose and is compared to <code>DEBUG_LEVEL</code>. Now my problem is, that in a statement like:</p>
  
  <pre><code>dputs 5, "#{big_class.inspect}"
  </code></pre>
  
  <p>the string is always evaluated, also if I set <code>DEBUG_LEVEL</code> to 1. And this evaluation can take a long time. My favourite solution would be something like:</p>
  
  <pre><code>dputs 5, '#{big_class.inspect}'
  </code></pre>
  
  <p>and then evaluate the string if desired. But I don't manage to get the string in a form I can evaluate. So the only think I could come up with is:</p>
  
  <pre><code>dputs( 5 ){ "#{big_class.inspect}" }
  </code></pre>
  
  <p>but this looks just ugly. So how can I evaluate a '#{}' string?</p>