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
Ernst T. wrote:
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
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