OK,更容易閱讀的代碼版本(我希望)紅寶石環路類問題
class First
attr_accessor :addresses
def initialize
address
end
def address
@addresses= []
File.open("/RubyDev/useful/lib/list/listtest.txt").each_line do |i|
@addresses << i.chomp
end
end
end
class Server1
b = Last.new
puts "Im Server1"
puts "Sending the following address to: #{b.loopaddress}"
end
class Server2
b = Last.new.loopaddress
puts "Im Server2"
puts "Sending the following address to: #{b.loopaddress}"
end
class Last
n=First.new
email_servers=[Server1.new,Server2.new]
def loopaddress
n.addresses.each_with_index do |i|
i % email_servers.length
end
end
end
只是想使循環地址可以在兩個服務器之間的時間唯一一個分佈。由於
'each_with_index'中的塊接收_two_參數,元素及其索引。 – 2010-07-14 18:47:32
謝謝,很高興知道 – rahrahruby 2010-07-14 21:03:20