I have the following code. I want to use the methods for myserver1 and myserver2 and pass them the addresses the have been iterated through in the send_to_servers method. I can’t seem to do that. Please help. Unless I can have these two receive addresses on an altering basis, I won’t be able to do what I need to do. Thanks in advance.
class Addresses
def add
@addresses = %w(me@gmail.com me2@gmail.com me3@gmail.com)
end
def myserver1
puts "Sending email from myserver1 with address #{@address}"
end
def myserver2
puts "Sending email from myserver2 with address #{@address}"
end
def servers
serv = [myserver1, myserver2]
end
# def servers
# serv = (1..2).to_a # Your list of servers goes here
# end
def send_to_servers(servers)
@addresses.each.with_index do |address, i|
server = servers[i % servers.length]
puts "Sending address #{address} to server #{server}"
@address = address
end
end
end
a = Addresses.new
a.add
servers = a.servers
a.send_to_servers(servers)
It’s unclear how you might want to structure it, but here is a concise implementation that I think meets your description.
Apologies if I’m missing something crucial to your problem with this. Please feel free to comment on what extra functionality is required to help firm up the specification.