def test(nr, &block) begin (1..3).each do |i| puts("test #{nr}, Iteration #{i}: Vor block.call") block.call(i) puts("test #{nr}, Iteration #{i}: Nach block.call") end puts("test #{nr}, Nach loop") ensure puts("test #{nr}: In ensure") end end def test1 test(1) { |i| break if(i == 2) } puts "test 1: end" end def test2 test(2) { |i| return if(i == 2) } puts "test 2: end" end class LoopInterrupt < StandardError end def test3 begin test(3) { |i| raise LoopInterrupt if(i == 2) } rescue LoopInterrupt => ex puts "test 3: rescue #{ex.message}" end puts "test 3: end" end (1..3).each { |i| eval("test#{i}") }