Solved

Ruby 2-D array

Posted on 2014-04-14
1
170 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now