What is catch and throw used for in Ruby?

Viewed 10515

In most other languages, the catch and throw statements do what the begin, rescue, and raise statements do in Ruby. I know the you can do this with these two statements:

catch :done do
  puts "I'm done."
end

and

if some_condition
  throw :done
end

But what is this useful for? Can somebody please give me an example of what catch and throw statements are used for in Ruby?

3 Answers
Related