변환 출력의 한 가지 기능으로 배열 및 공급 값으로 변수에 다른 함수에서 루비

0

질문

에 대한 하나의 루비 프로그램 논리를 변환할 문자열을 출력의 한 가지 기능으로 배열 및 배열에서는 공급하는 값을 변수를 선언에 다른 기능의 프로그램

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

10.1.1.1
10.1.1.2
10.1.1.3

이 출력으로 변환해야 배열과 급에서 값으로 별도의 함수의 동일한 프로그램

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

그래서 출력의 filter_pattern,해야 합 아래와 같이

   '[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

최고의 응답

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 지만,aws 콘솔 볼 수 있었던 w6!="#{ips[0]}"&&w6!="#{ips[1]}*&&w6!="*#{ips[2]}"]'출력하는 대신 해당 Ip 에서 배열
Kavitha

@카비타기는 그것이 무엇인지 명확하지 않을 의미의 댓글
user1678123

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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