settings = [ ['127.0.0.1', 80], ['0.0.0.0', 443] ]
How can I do:
settings.each do |ip, port|  
    ...
end
Instead of:
settings.each do |config|  
    ip, port = *config
    ...
end
                Your first example works because Ruby will destructure block arguments. See this article for more information on destructuring in ruby.
The method you're looking for is Array#map
settings = [ ['127.0.0.1', 80], ['0.0.0.0', 443] ]
settings.map { |ip, port| puts "IP: #{ip} PORT: #{port}"  } 
which will return
    #// => IP: 127.0.0.1 PORT: 80
    #// => IP: 0.0.0.0 PORT: 443
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With