a = [nil, nil, nil, 'hoge']
b = Array.new a #set same data
def get ar, rc
return "Couldn't get data in retry count" if rc == 0
puts "Trying get data..."; sleep 3
dat = ar.shift
return "Found!: \"#{dat}\"" unless dat.nil?
puts 'data not found. retrying...'; sleep 1
get ar, rc - 1
end
puts get a, 3
puts '--------------'
puts get b, 4
# Out put:
=begin
Trying get data...
data not found. retrying...
Trying get data...
data not found. retrying...
Trying get data...
data not found. retrying...
Couldn't get data in retry count
--------------
Trying get data...
data not found. retrying...
Trying get data...
data not found. retrying...
Trying get data...
data not found. retrying...
Trying get data...
Found!: "hoge"
=end