我希望我的方法只返回关注者的数量。我发现如果它没有进行到最后一个“if”语句,它只会返回查询或前一个代码的哈希值。
def my_twitter_followers
if JSON.parse(contact_hash)["social_profiles"]
JSON.parse(contact_hash)["social_profiles"].each do |profile|
if profile["followers"]
return profile["followers"]
end
end
end
end
如果 Twitter 个人资料存在于包含哈希的 social_profiles 数组中,我希望它返回关注者(因此为什么以下 ["followers"]
[{"url"=>" http://gravatar.com/xxxxxx ", "id"=>"xxxxxx", "type"=>"gravatar", "type_id"=>"gravatar", "type_name"= >“Gravatar”、“用户名”=>“xxxxxxx”、“bio”=>“SOME LARGE BIO”}、{“url”=>“ http://www.facebook.com/xxxxxxx ”、“type”= >"facebook", "type_id"=>"facebook", "type_name"=>"Facebook", "username"=>"xxxxxx", "id"=>"xxxxxx"}, {"url"=>" http ://www.quora.com/xxxxxxx ", "类型"=>"quora", "用户名"=>"xxxxxx", "type_id"=>"quora", "type_name"=>"Quora"}, {"url"=>" http://twitter.com/xxxxxxx ", "type"=>"twitter", "username"=> "xxxxx", "type_id"=>"twitter", "followers" => "1000" "type_name"=>"Twitter"}, {"url"=>" http://plancast.com/user/xxxxxx=>” http://plancast.com/user/xxxxxx=>” http://plancast.com/user/xxxxxx", "id"=>"xxxxxx", "type"=>"plancast", "type_id"=>"plancast", "type_name"=>"Plancast"}, {"url"=>" http:// youtube.com/user/xxxxxxx ", "type"=>"youtube", "username"=>"xxxxxx", "type_id"=>"youtube", "type_name"=>"Youtube"}]
谢谢!