我正在構建一個與Highrise集成的應用程序,然而,當嘗試導入一個人時,它會吐出類似如下的巨大哈希:Rails,在複雜的哈希中查找對象
[ ..., #<Highrise::Person:0x1035084b8 @attributes={"contact_data"=>#<Highrise::Person::ContactData:0x1034f8b30 @attributes={"email_addresses"=>[], "addresses"=>[], "web_addresses"=>[], "phone_numbers"=>[], "twitter_accounts"=>[], "instant_messengers"=>[]}, @prefix_options={}>, "created_at"=>Sat Nov 28 05:38:26 UTC 2009, "title"=>"president", "updated_at"=>Sat Nov 28 05:38:27 UTC 2009, "background"=>"asdfasdfadsfas", "id"=>27569370, "owner_id"=>nil, "group_id"=>nil, "company_id"=>27569371, "last_name"=>"Doe", "author_id"=>192208, "visible_to"=>"Everyone", "first_name"=>"John"}, @prefix_options={}>, ... ]
它看起來像裏面的每個Highrise::Person
是@attributes
這是另一種Highrise::Person::ContactData
,這本身就是另一種@attributes
與像email_addresses[]
和phone_numbers[]
陣列以及簡單的鍵/值對不對......
抱歉如此混亂,我想知道的我如何才能從這樣的散列中獲得每個人的first_name
?
大概是超級簡單,我只是困惑......
更新
我猜短語這將是一個更好的辦法,因爲上面的哈希,爲什麼不這項工作:
@people = Highrise::Person.find(:all)
for person in @people do
person.attributes["first_name"]
end