Accessing Array

E

Ernst Tanaka

record => [#<Quote:0xb189218
@attributes={"underlying"=>"$ADVN", "price"=>"1579.00",
"date"=>"2007-11-08 17:01:13", "id"=>"3362", "impvolatility"=>nil,
"volume"=>nil}>,
#<Quote:0xb1877ec @attributes={"underlying"=>"$ADVN",
"price"=>"1579.00", "date"=>"2007-11-08 16:49:15", "id"=>"3351",
"impvolatility"=>nil, "volume"=>nil}>]



The above array is the result from a record.find:)all) sql call in Ruby.

I need to access attribute price of the second entry of the array.
I have some problem coding it.

I tried record.price[1] but that seems not to be the solution.

Thanks for your help,

Ernst
 
J

Jeremy Woertink

Ernst said:
record => [#<Quote:0xb189218
@attributes={"underlying"=>"$ADVN", "price"=>"1579.00",
"date"=>"2007-11-08 17:01:13", "id"=>"3362", "impvolatility"=>nil,
"volume"=>nil}>,
#<Quote:0xb1877ec @attributes={"underlying"=>"$ADVN",
"price"=>"1579.00", "date"=>"2007-11-08 16:49:15", "id"=>"3351",
"impvolatility"=>nil, "volume"=>nil}>]



The above array is the result from a record.find:)all) sql call in Ruby.

I need to access attribute price of the second entry of the array.
I have some problem coding it.

I tried record.price[1] but that seems not to be the solution.

Thanks for your help,

Ernst

You are very close. You called index 1 on an attribute, and you should
call it on the array. record is your array, and you have 2 quote
objects, so doing record[1] would return the second Quote object, and
doing record[1].price would return 1579.00


~Jeremy
 
E

Ernst Tanaka

Hi Jeremy:

Thank you!

I spend some hours finding the solution in books and on the net.

Your solution worked!

I am new to Ruby programing, making great progress, only sometimes I
have a 'hang up'.

Thanks,

Ernst
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,351
Members
48,036
Latest member
nickwillsonn

Latest Threads

Top