xxxxxxxxxx
# Ruby Program of Catch and Throw Exception
gfg = catch(:divide) do
# a code block of catch similar to begin
number = rand(2)
throw :divide, 10 if number == 0
number # set gfg = number if
# no exception is thrown
end
puts gfg
xxxxxxxxxx
# Ruby Program of Catch and Throw Exception
gfg = catch(:divide) do
# a code block of catch similar to begin
number = rand(2)
throw :divide if number == 0
number # set gfg = number if
# no exception is thrown
end
puts gfg
xxxxxxxxxx
# Ruby Program of Catch and Throw Exception
gfg = catch(:divide) do
# a code block of catch similar to begin
100.times do
100.times do
100.times do
number = rand(10000)
# comes out of all of the loops
# and goes to catch statement
throw :divide, 10 if number == 0
end
end
end
number # set gfg = number if
# no exception is thrown
end
puts gfg
xxxxxxxxxx
# Ruby program to demonstrate
# the include? method
# Taking a string and
# using the method
puts "Ruby".include? "by"
puts "String".include? "ui"
xxxxxxxxxx
# Ruby program to demonstrate
# the include? method
# Taking a string and
# using the method
puts "Sample".include? "am"
puts "Input".include? "pt"