Converting output of one function into array and feed value into variable in other function in ruby
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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.
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)
"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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.