store all the values in a new array

Discussion in 'Ruby' started by Remco Swoany, Feb 26, 2009.

  1. Remco Swoany

    Remco Swoany Guest

    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
    --
    Posted via http://www.ruby-forum.com/.
    Remco Swoany, Feb 26, 2009
    #1
    1. Advertising

  2. 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:

    > 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
    > --
    > Posted via http://www.ruby-forum.com/.
    >


    --
    Florian Gilcher

    smtp:
    jabber:
    gpg: 533148E2
    Florian Gilcher, Feb 26, 2009
    #2
    1. Advertising

  3. [Note: parts of this message were removed to make it a legal post.]

    On Thu, Feb 26, 2009 at 4:39 AM, Florian Gilcher <>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
    --
    http://antoniocangiano.com - Zen and the Art of Programming
    http://math-blog.com - Mathematics is wonderful!
    http://stacktrace.it - Aperiodico di resistenza informatica
    Follow me on Twitter: http://twitter.com/acangiano
    Recently completed "Ruby on Rails for Microsoft Developers" for Wrox.
    Antonio Cangiano, Feb 26, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    to store or not to store an image

    =?Utf-8?B?UnVkeQ==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    636
    =?Utf-8?B?UnVkeQ==?=
    Mar 30, 2005
  2. Jim in Arizona
    Replies:
    4
    Views:
    7,951
    Jim in Arizona
    Aug 24, 2005
  3. Al Hatch
    Replies:
    3
    Views:
    971
    Johannes Koch
    Jun 5, 2006
  4. Replies:
    7
    Views:
    259
    Barry Schwarz
    Dec 12, 2006
  5. Replies:
    2
    Views:
    455
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page