Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4622

Break out a loop from within a (yielded) block inside the loop

$
0
0
jobs.each do |job|  msg job.name do    break if stop_all_jobs?    job.run!  endend   def msg(msg, &block)  puts 'START '+ msg  yield  puts 'END '+ msgend

In the above example break does not break out of the loop as expected. It only breaks out of the msg code block.

This seems a little odd, but I guess it is based on context, that said, how do I break out of the loop from code which is within a yielded code block?


Viewing all articles
Browse latest Browse all 4622


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>