Passing multiple codeblocks as arguments

Posted by doctororange on Stack Overflow See other posts from Stack Overflow or by doctororange
Published on 2010-03-17T15:36:48Z Indexed on 2010/03/17 15:41 UTC
Read the original article Hit count: 428

Filed under:
|
|

I have a method which takes a code block.

  def opportunity
    @opportunities += 1
    if yield
      @performances +=1
    end
  end

and I call it like this:

opportunity { @some_array.empty? }

But how do I pass it more than one code block so that I could use yield twice, something like this:

   def opportunity
     if yield_1
       @opportunities += 1
     end
     if yield_2
       @performances +=1
     end
   end

and:

opportunity {@some_other_array.empty?} { @some_array.empty? }

I am aware that this example could be done without yield, but it's just to illustrate.

Thanks.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about yield