การเปลี่ยนผลลัพธ์ของหนึ่งฟังก์ชันเข้าไปในอาเรย์และแหล่งป้อนค่าในตัวแปรในอีกฟังก์ชันในรูบี้

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]}"]'แสดงผลแทนที่จะเป็นที่สัมพันธ์กัน IPs อยู่ในตารางคู่ลำดับ
Kavitha

@Kavitha เจาะจงกว่านี้มันไม่ได้ชัดเจนว่าอะไรที่คุณหมายถึงความเห็นของเธอ
user1678123

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่