Conversione di output di una funzione in un array e mangimi valore variabile in funzione in ruby

0

Domanda

Per uno di ruby logica di programmazione, sto cercando di convertire la stringa di output di una funzione in un array e array necessario per nutrire i valori per le variabili dichiarate nell'altra funzione del programma

//response.each do |instance |
  print "#{instance.private_ip_address}"
  print "\n"
  end
//

10.1.1.1
10.1.1.2
10.1.1.3

Questa uscita dovrebbe essere convertito in un array e mangimi come valori separati funzione del programma stesso

def run_me
    ::
    ::
    filter_pattern = '[w1,w2,w3,w4,w5,w6!="*#{array[0]}*"&&w6!="*#{array[1]}*&&w6!="*#{array[2]}*"]'

In modo che l'output di filter_pattern , dovrebbe essere come di seguito

   '[w1,w2,w3,w4,w5,w6!="*10.1.1.1*"&&w6!="*10.1.1.2*"&&w6!="*10.1.1.3*"]'
aws-sdk aws-sdk-ruby ruby
2021-11-22 14:48:07
1

Migliore risposta

0
# Mocked responses for the sake of the example..
responses = [
  OpenStruct.new(request_type: 'GET', private_ip_address: '10.1.1.1'),
  OpenStruct.new(request_type: 'GET', private_ip_address: '10.1.1.2'),
  OpenStruct.new(request_type: 'GET', private_ip_address: '10.1.1.3')
]

data_of_ips = [] # Storing ips in this array from the loop for later usage in run_me method

responses.each do |instance|
  data_of_ips << instance.private_ip_address
end

# Now calling the run_me and pass the array as argument

run_me(data_of_ips)

# replace it in your filter like this
def run_me(ips)
  # 
  # 
  filter_pattern = '[w1,w2,w3,w4,w5,w6!="*#{ips[0]}*"&&w6!="*#{ips[1]}*&&w6!="*#{ips[2]}*"]'^Z
end
2021-11-22 20:09:16

user1678123, ma nel aws console ho potuto vedere il w6!="#{ips[0]}"&&w6!="#{ips[1]}*&&w6!="*#{ips[2]}"]' uscita invece del corrispondente IPs nell'array
Kavitha

@Kavitha essere più specifico non è chiaro cosa vuoi dire con il tuo commento
user1678123

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................