# Store all the values in a new array

**URL:** <https://www.ruby-forum.com/t/store-all-the-values-in-a-new-array/161414>\
**Category:** Ruby\
**Created:** [February 26, 2009, 10:13am UTC](https://www.ruby-forum.com/t/store-all-the-values-in-a-new-array/161414 "2009-02-26T10:13:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [February 26, 2009, 10:13am UTC](https://www.ruby-forum.com/t/store-all-the-values-in-a-new-array/161414/1 "2009-02-26T10:13:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [February 26, 2009, 10:40am UTC](https://www.ruby-forum.com/t/store-all-the-values-in-a-new-array/161414/2 "2009-02-26T10:40:47Z")

</div>

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 S. 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/](http://www.ruby-forum.com/).

–  
Florian G.

smtp: removed\_email\_address@domain.invalid  
jabber: removed\_email\_address@domain.invalid  
gpg: 533148E2

---

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [February 26, 2009, 2:19pm UTC](https://www.ruby-forum.com/t/store-all-the-values-in-a-new-array/161414/3 "2009-02-26T14:19:17Z")

</div>

On Thu, Feb 26, 2009 at 4:39 AM, Florian G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)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
