开发者

Formatting Data from Hashie

How do you format the data output from a call to twitter (for example). My output's in the following format:

<#Hashie::Mashcontributors=nil coordinates=nil created_at="Wed May 04 18:57:32 +0000 2011" favorited=false geo=nil id=65852579048980480 id_str="65852579048980480" in_reply_to_screen_name=nil in_reply_to_status_id=nil in_reply_to_status_id_str=nil in_reply_to_user_id=nil in_reply_to_user_id_str=nil place=nil retweet_count=0 retweeted=false source="web" text="what's happening?" truncated=false user=<#Hashie::Mash contributors_enabled=false created_at="Wed May 04 09:17:26 +0000 2011" default_profile=true default_profile_image=true 开发者_C百科description=nil favourites_count=0 follow_request_sent=false followers_count=0 following=false friends_count=0 geo_enabled=false id=292829579 id_str="292829579" is_translator=false lang="en" listed_count=0 location=nil name="PSTest" notifications=false profile_background_color="C0DEED" profile_background_image_url="http://a3.twimg.com/a/1304436748/images/themes/theme1/bg.png" profile_background_tile=false profile_image_url="http://a1.twimg.com/sticky/default_profile_images/default_profile_0_normal.png" profile_link_color="0084B4" profile_sidebar_border_color="C0DEED" profile_sidebar_fill_color="DDEEF6" profile_text_color="333333" profile_use_background_image=true protected=false screen_name="PSTest4" show_all_inline_media=false statuses_count=8 time_zone=nil url=nil utc_offset=nil verified=false>>

As a newbie, this just looks like junk to me!! I'm trying to display the latest 10 tweets from users on my app. Just don't know how to get started...

B

== edit ==

In order to display the text only, I've now tried the following.

<%= @user.twitter_token.timeline.each do |t| %>
<%= t.text %>
<% end %>

Although I get no errors, I can see the correct output but there hash still lingers after the output. Not sure why.

Thanks


Hashie lets you access things using dot notation (e.g. @tweet.created_at instead of @tweet["created_at"].

So assuming the object you posted is @tweet, you could do this:

@tweet.coordinates
# => nil
@tweet.user.name
# => "PSTest"
@tweet.text
# => "what's happening?"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜