Solved

Ruby 2-D array

Posted on 2014-04-14
1
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
extending out dates 4 299
Java - confuse using abstract class and class 13 519
SSH Rail Server Command 7 1,001
Upgrading Ruby & Rails on CentOS 3 443
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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