Forum: Ruby store all the values in a new array

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
28be3be213eeed3f66e0a20f1e20c7ac?d=identicon&s=25 Remco Swoany (zwaan123)
on 2009-02-26 10:13
Hi,

the array below is the output from a find(:all)

[#<Boekingen affnr: "vl999", pnr: "MA5OSG", agent: "monties",
ticket_prijs: #<BigDecimal:b775f4c4,'0.138E3',4(12)>, aantal_pers: 2,
ticket_fees: nil, res_kosten: nil, commissie: nil, ticket_verz: nil,
tax: nil, total_prijs: #<BigDecimal:b775f230,'0.36316E3',8(12)>, bet_id:
nil, vertrek_id: "AMS", bestemming_id: "MAD", airline_id: "HV",
cabinclass: nil, type: nil, eligibility: nil, supplier: nil, heen_datum:
1020204000, terug_datum: 1049061600, outbound_v: nil, outbound_a: nil,
outbound_vluchtnrs: nil, inbound_v: nil, inbound_a: nil,
inbound_vluchtnrs: nil, reis_verz: #<BigDecimal:b775ed08,'0.0',4(8)>,
annu_verz: #<BigDecimal:b775eccc,'0.0',4(8)>, boeking_status: nil,
enquete_status: 1, holiday_status: 0, eurenq_status: 9, nieuwsbrief: 99,
reference: nil, kadoboncode: nil, boeking_tijdcode: 1030624003,
servicemail_status: nil, factory_master_id: 1>,] ectect

Now i want to store all the values of the "ticket_fees" in a new array.

like this...

ticket_fee = ["2", "3", "1"]

How can i do this(newbie)

Thanks..remco
D1f1c20467562fc1d8c8aa0d328def62?d=identicon&s=25 Florian Gilcher (skade)
on 2009-02-26 10:40
(Received via mailing list)
values = ary.collect {|elem| elem.ticket_fees }

In Rails and newer Ruby environments, you can also do this:

values = ary.collect( &:ticket_fees )

On Feb 26, 2009, at 10:12 AM, Remco Swoany wrote:

> cabinclass: nil, type: nil, eligibility: nil, supplier: nil,
> Now i want to store all the values of the "ticket_fees" in a new
> Posted via http://www.ruby-forum.com/.
>

--
Florian Gilcher

smtp:   flo@andersground.net
jabber: Skade@jabber.ccc.de
gpg:    533148E2
6111b4012d1401ca83fdcea6b1d71237?d=identicon&s=25 Antonio Cangiano (Guest)
on 2009-02-26 14:19
(Received via mailing list)
On Thu, Feb 26, 2009 at 4:39 AM, Florian Gilcher
<flo@andersground.net>wrote:

> values = ary.collect {|elem| elem.ticket_fees }
>
> In Rails and newer Ruby environments, you can also do this:
>
> values = ary.collect( &:ticket_fees )
>

But be careful with the latter form (known as "symbol to proc"). In Ruby
1.8
it's much slower than using a regular block.

Cheers,
Antonio
This topic is locked and can not be replied to.