Thank you very much Jes=FAs Gabriel y Gal=E1n but some confusion please
explain with different catch and throw,not include same both are same
block take as a different ,please.
I'm not sure I understand your question. The way it works is that when
you throw, Ruby looks up through the stack for a catch with the same
symbol. If it finds it, the block passed to catch is terminated
immediately, and the block returns the value passed to throw. This is
useful to exit from a deeply nested structure, for example (based on
http://phrogz.net/programmingruby/tut_exceptions.html) :
def processValue value
throw :quit if value =3D~ /quit!/i
value.downcase
end
def promptAndGet(prompt)
print prompt
value =3D gets.chomp
processValue value
end
catch :quit do
name =3D promptAndGet "Name: "
age =3D promptAndGet "Age: "
sex =3D promptAndGet "Sex: "
#do_something_with name, age, sex
end
You can nest catch blocks:
catch
first_level) do
puts "at first level"
catch
second_level) do
puts "At second level"
if (rand(2) =3D=3D 0)
throw :second_level
else
throw :first_level
end
puts "still in second level"
end
puts "still in first level"
end
Jesus.