Nice writeup.
I noticed that catch and throw was missing.
def using_throw arr
arr.each do |i|
throw :early if i > 5
puts arr[i]
end
end
catch :early do
using_throw [1, 2, 3, 4, 5, 6, 7, 8]
end
Demonstrates that the catch does not need to be in the same method.
def using_throw arr
catch :early do
arr.each do |i|
throw :early if i > 5
puts arr[i]
end
end
end
using_throw [1, 2, 3, 4, 5, 6, 7, 8]
If we want to catch in the method itself.