Created
November 26, 2013 23:02
-
-
Save gouf/7667873 to your computer and use it in GitHub Desktop.
再帰処理で再試行してみる。データ取得は他の関数にやらせるといいかも。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment