Kaye Ng wrote in post #1071965:
>>> Another thing I don't understand is that when I remove the ".first", run
>>> the program, enter a valid id or name, or just about anything really, it
>>> results in:
>>
>> Because .execute returns an array of hashes (even if this array only
>> has one item). .first the chooses only the first one of them.
>>
>> -- Matma Rex
>
> Thank you Rex, but how is it an array of hashes?
>
> 'puts person.inspect' returns:
>
> {"id"=>3, "name"=>"Dave Ellefson", "job"=>"Bassist", "gender"=>"Male",
> "age"=>47, 0=>3, 1=>"Dave Ellefson", 2=>"Bassist", 3=>"Male", 4=>47}
>
> Isn't {key => value, key => value, etc. etc} just a Hash? (not an array
> of hashes)

If you remove the .first, you should see

[{"id"=>3, "name"=>"Dave Ellefson", ...}]

The outer [...] shows that you have an Array, containing one element.

Another thing to try is looking at the class of the object. e.g.

  result = $db.execute("SELECT * FROM people WHERE name = ? OR id = ?",
           idorname, idorname.to_i)   # without .first
  puts result.class, result.inspect
  person = result.first
  puts person.class, person.inspect

-- 
Posted via http://www.ruby-forum.com/.