views:

27

answers:

2

Hi Guys, quick question.

If I type in my console

u = User.first
u.friends(&map:username)

I geht ["Peter", "Mary", "Jane"]

But I also want to show the birthday, so how do I do that?

u.friends(&map:username, &map:birthday)

doesn't work thanks in advance

+2  A: 

you can use the alternate block syntax:

u.friends.map{|f| [f.username, f.birthday]}

would give an array of arrays

u.friends.map{|f| "#{f.username} - #{f.birthday}"}

would give you an array of strings... you can do quite a bit from there.

Geoff Lanotte
Thankyou,thankyou,thankyou
tabaluga
+1  A: 

Try

u.friends.map {|friend| [friend.username, friend.birthday]}

The & syntax is simply a shorthand to the underlying Ruby method.

Chris
and thankyou,thankyou,thankyou to you too :)
tabaluga
It's nice to say thank-you, you can also say thank-you by ticking the up-arrow and indicating that an answer was useful.
Steve Weet