?
Solved

Ruby 2-D array

Posted on 2014-04-14
1
Medium Priority
?
211 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 2000 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

Independent Software Vendors: 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

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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

771 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