 
 This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.
| Stopping an Iteration | ||
|---|---|---|
| Code | Expected | Actual | 
| 1.upto(10) do |x| puts x break if x == 3 end | 1 2 3 | 1 2 3 | 
| block = Proc.new do |x| puts x break if x == 3 puts x + 2 end block.call(5) | 5 7 | 5 7 | 
| block.call(3) | 3 LocalJumpError: break from proc-closure ... | 3 LocalJumpError: break from proc-closure from (irb):7:in `call' from (irb):11 | 
| def find(*paths)
  paths.each do |p|
    catch(:prune) do     
      #Process p as a file or directory...
    end
    # When you call Fine.prune you'll end up here.
  end
end
def prune
  throw :prune
end | nil | |