LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2021, 01:26 PM   #1
Sivagurunathan
LQ Newbie
 
Registered: Aug 2008
Posts: 2

Rep: Reputation: 0
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]}*"]'
 
Old 11-22-2021, 01:52 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 24,296

Rep: Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140
Quote:
Originally Posted by Sivagurunathan View Post
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.
 
Old 11-23-2021, 10:04 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,852

Rep: Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111
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)
 
1 members found this post helpful.
Old 11-23-2021, 10:38 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,434
Blog Entries: 4

Rep: Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375
"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.
 
  


Reply

Tags
aws, ruby, sdk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] reference bash array values, using a variable with a value of the array name gusthecat Programming 5 03-07-2012 04:41 PM
strange value assignments variable = value, value?? ostrow30 Programming 2 07-24-2011 08:59 AM
difference between value *value and value * value PoleStar Linux - Newbie 1 11-26-2010 04:37 PM
Bash Variable Array, Trying to add another value into the array helptonewbie Linux - Newbie 6 03-03-2009 12:18 AM
function showing a list of variable and value: (dynamic variable name) budhax Linux - Newbie 1 09-19-2008 08:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration