문제

그러나 사람을 가져 오려고 할 때 Highrise와 너무나도 좋은 앱을 구축하고 있습니다. Highrise::People 이와 비슷한 거대한 해시를 뱉어냅니다.

[ ...,  #<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
도움이 되었습니까?

해결책

만약에 당신의 목록 사람들의 배열입니다

yourlist.each do |person|
    puts person.attributes["first_name"]
end

만약에 사람 attr_reader가 있습니다.

다른 팁

당신은 또한 할 수 있습니다 :

@people.each do |person|
    puts person.first_name
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top