title: Find Groovy Closure by name
body: <p>I try to call a dynamic closure in Groovy, and I'm stuck right now. I have the name, but I don't know how to reference it with the <code>call()</code> method</p>
  
  <p>Here is a small example of what I want to achieve:</p>
  
  <pre><code>def fooClos = { println foo }
  def barClos = { println bar}
  def c = new Random().nextInt() % 2 == 0 ? "foo" : "bar"
  "${c}Clos".call()
  </code></pre>
  
  <p>So the last line should either print <code>foo</code> or <code>bar</code></p>
  
  <p>I also tried</p>
  
  <pre><code>this."${c}Clos".call()
  </code></pre>
  
  <p>and</p>
  
  <pre><code>this.&amp;"${c}Clos".call()
  </code></pre>
  
  <p>without any success.<br>
  So can someone help me how the correct reference has to look? I can probably work around my problem, but I still want to know how it is done.</p>