Pairing Data 2-D array

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?

You can do an array of arrays:

a.b.map {|x| [x.c, x.d]}

2014-04-14 18:12 GMT-03:00 Jan Yo [email protected]:

a.b.map{ |x| x.c}
c3 c3
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit

https://groups.google.com/d/msgid/rubyonrails-talk/d523e7b0f6a6396078ba06c074e8e9c7%40ruby-forum.com

.
For more options, visit https://groups.google.com/d/optout.


Att, Antônio Augusto de Sousa Britto - 43ª turma de Ciência da
Computação -
UFU