Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Accessing Array
Ernst Tanaka
11/8/2007 10:19:00 PM
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
--
Posted via
http://www.ruby-...
.
2 Answers
Jeremy Woertink
11/9/2007 12:02:00 AM
0
Ernst Tanaka 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
--
Posted via
http://www.ruby-...
.
Ernst Tanaka
11/9/2007 12:56:00 AM
0
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
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Accessing Array
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password