title: How can I pass a block/proc and variable directly to a function?
body: <p>I'm trying to learn about blocks and procs and I feel like this should be doable, but so far I haven't been successful.</p>
  
  <p><strong>What I'd like:</strong></p>
  
  <pre><code>def main_action(generic_variable, block)
   generic_variable += 1 # I do more interesting stuff than this in my version
   yield(generic_variable)
  end
  
  main_action(3, {|num| num + 5 })
  </code></pre>
  
  <p>Or something similar.</p>
  
  <p>The closest I found was <a href="http://mudge.name/2011/01/26/passing-blocks-in-ruby-without-block.html" rel="nofollow">http://mudge.name/2011/01/26/passing-blocks-in-ruby-without-block.html</a> which seemed to require creating a passing method to send the blocks around:</p>
  
  <pre><code>class Monkey
  
    # Monkey.tell_ape { "ook!" }
    # ape: ook!
    #  =&gt; nil
    def self.tell_ape(&amp;block)
      tell("ape", &amp;block)
    end
  
    def self.tell(name, &amp;block)
      puts "#{name}: #{block.call}"
    end
  end
  </code></pre>
  
  <p>If I use the same passing method set up in my code I can get it to work, but it seems like unnecessary code. I tried calling <code>Monkey.tell("ape", { "ook!" })</code> directly, but got <code>syntax error, unexpected '}', expecting tASSOC</code></p>
  
  <p>Is it possible to send a variable and a block (or proc, I'm not picky) to a function in one call? Also, if you have time, what's going on above? Why doesn't that work?</p>