>>     person = {
>>         :name => "John Doe",
>>         :age => 20
>>     }
>
> But wouldn't write code like the above. I would create a class
> "Person" instead. Hashes with a fixed set of keys are almost
> screaming for you to create a new class.

I've thought of doing that, but I found certain properties of the hash
to be convenient. For example, Hash#keys will tell me the name of all
the fields inside the hash. Then, if I have a "person" object as
defined above, storing it into SQL is pretty simple:

(code not tested, but should be more or less right)

def insert(table, hash)
    Db.do "INSERT INTO #{table} SET #{
        #{hash}.to_a.collect {
            |key, value| "#{key} = #{Mysql.quote(value)}"
        }.join(", ")
    }"
end

insert('person', person)

When I do it with a class, there doesn't seem to be a way to get a
list of all the attributes in the class. (Or is there? If there was a
good way, I think it would be better for me to use classes since then
I get all the other nice features of classes.)