LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Converting output of one function into array and feed value into variable in other function in ruby (https://www.linuxquestions.org/questions/programming-9/converting-output-of-one-function-into-array-and-feed-value-into-variable-in-other-function-in-ruby-4175703936/)

Sivagurunathan 11-22-2021 12:26 PM

Converting output of one function into array and feed value into variable in other function in ruby
 
For one of ruby programming logic, am trying to convert the string output of one function into an array and from array have to feed the values to the variables declared in other function of the program

Code:

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

10.1.1.1
10.1.1.2
10.1.1.3

This output should be converted into array and feed as values in separate function of same program

Code:

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


TB0ne 11-22-2021 12:52 PM

Quote:

Originally Posted by Sivagurunathan (Post 6303485)
For one of ruby programming logic, am trying to convert the string output of one function into an array and from array have to feed the values to the variables declared in other function of the program
Code:

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

10.1.1.1
10.1.1.2
10.1.1.3

This output should be converted into array and feed as values in separate function of same program
Code:

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


Ok...so is there a question here?? Are you asking us to write this for you?? Because we can see what you WANT, but can't see any effort on your part to do it; read the "Question Guidelines" and the LQ Rules.

Show us what you have done/tried to accomplish your goals and tell us where you're stuck, and we can try to help.

grail 11-23-2021 09:04 AM

Have to say, I am with TB0ne on this one. There is little to no information on what is stored in the response object and what the format is, but as a start I would probably look at .to_a method
You show no real way of how the newly aquired array is being used as your current example where I see the word 'array' is a string

Help us to help you and maybe tackle each part separately and ask questions on what exactly it is you are stuck on? (ie not how to do it)

sundialsvcs 11-23-2021 09:38 AM

"Online forums are not a programming (or a homework ...) service." We can sometimes assist in answering specific questions given short, complete examples of where you may be stuck.


All times are GMT -5. The time now is 11:20 PM.