From: "Aleksi Niemelä" Date: 2000-07-13T22:10:10+02:00 Subject: [ruby-talk:03978] Associating block to block call? What are my chances to associate block to a block call? The following example does not call any of associated blocks: block = proc { # |&bl| # causes parse error |bl| puts "in block" puts("call passed: "+bl.call) if bl puts(yield) if iterator? "return" } puts "1)" puts block.call puts puts "2)" puts block.call do puts "associated iterator" end puts puts "3)" puts block.call( proc{"passed proc object"} ) puts def block_assoc(block, &associated_block) puts "4)" associated_block.call puts block.call end def block_assoc2(block) puts "5)" yield puts block.call end block_assoc( block ) do puts "testing associated blocks" end puts block_assoc2( block ) do puts "testing associated blocks" end ################ Outputs: 1) in block return 2) in block return 3) in block call passed: passed proc object return 4) testing associated blocks in block return 5) testing associated blocks in block return ##################### This is a example demonstrates the effect of context. The block2 yields without reason. block1 = proc { puts "block1" yield if iterator? # should't be yielded } def block2 proc { puts "block2" yield if iterator? # should't be yielded } end block1.call block2.call block1 block2 block_iterator_2.rb:8:in `block2': yield called out of iterator (LocalJumpError) from block_iterator_2.rb:7:in `call' from block_iterator_2.rb:13 - Aleksi