Problem with select

I have this statement
ids = athlete.leagues.select(“league_id”).map(&league_id)

getting this error
Subject: [] athlete_injuries#create (TypeError) “wrong argument type
Fixnum
(expected Proc)”

Anyone know what is going on here?

by the way not a girl :slight_smile:
gerbdla = gerber david los angeles
long story.

On 5 Dec 2011 22:48, “gerbdla” [email protected] wrote:

I have this statement
ids = athlete.leagues.select(“league_id”).map(&league_id)

What is it that you’re trying to do with this statement? The closest i
can
guess is the following:

ids = athlete.leagues.select{|league|league.id =
league_id}.map(&:league_id)

But that just gives an array of league_ids the same as the one you
started
with.

Instead this worked. Not sure exactly why the other works and not
select.

athlete.leagues.collect(&:league_id)

On 6 December 2011 02:36, gerbdla [email protected] wrote:

Instead this worked. Not sure exactly why the other works and not
select.

athlete.leagues.collect(&:league_id)

because “.select” returns only those elements that return true to an
evaluation, while “.collect” returns the result of the block passed to
every element. Have a look at the Enumerable and Array api pages.
http://www.ruby-doc.org/core-1.9.3/Enumerable.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs