使用普通哈希函数,可以通过此方法获取键:
hash.keys
如何获取一个类似于以下多维哈希表的第二个维度的键:
{"<id>"=>{"first_name"=>"test", "last_name"=>"test_l", "username"=>"test_user",
"title"=>"Sales Manager", "office"=>"test", "email"=>"test@test.com"}}
<id>
是每个项目的唯一标识。
因此,我想要上面列出的键:first_name, last_name, username, title, office and email
hash["<id>"].keys
更加正确。原帖中展示的键是字面字符串。 - the Tin Man