Solved

Ruby 2-D array

Posted on 2014-04-14
1
174 Views
Last Modified: 2014-06-08
I have class A.
I have a class B with attributes c and d.
A has many Bs.

I get an instance of A using
a = find_by....

I can get a listing (enumeration) of values for attribute b using map
function.

   a.b.map{ |x| x.c}

c1
c2
c3

However, I want c and d returned and paired together in an array like a
2-d array.

c1  d1
c2  d2
c3  c3

What's the best way to do this?  Map won't work, correct?
0
Comment
Question by:lcor
1 Comment
 
LVL 7

Accepted Solution

by:
roshkins earned 500 total points
ID: 40084869
So you're very close. What you want to do is this:
a.b.map{ |x| [x.c, x.d] }

Open in new window


This will result in an array of arrays, which is what you seem to want.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question