Hi guys! This is just a part of the code of a program that can load a
database file, add a table in it, and find an entry (a person).
def find_person
puts "Enter name or ID of person to find:"
idorname = gets.chomp #i would pronounce the variable as "ID or
Name"
person = $db.execute("SELECT * FROM people WHERE name = ? OR id = ?",
idorname, idorname.to_i).first
unless person
puts "No result found"
return
end
puts %Q{Name: #{person['name']}
Job: #{person['job']}
Gender: #{person['gender']}
Age: #{person['age']}}
end
I understand most of it except the fourth line. Notice the ".first" at
the end of the $db.execute code.
Can anyone explain its significance please. Thanks so much!
···
--
Posted via http://www.ruby-forum.com/.