我有一個看起來像這樣的數組。拼合紅寶石陣列
[{"title"=>"ga:browser=Internet Explorer", "dimensions"=>[{:browser=>"Internet Explorer"}], "metrics"=>[{:pageviews=>2047}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Internet%20Explorer&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=Safari", "dimensions"=>[{:browser=>"Safari"}], "metrics"=>[{:pageviews=>1196}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Safari&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=Firefox", "dimensions"=>[{:browser=>"Firefox"}], "metrics"=>[{:pageviews=>835}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Firefox&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=Chrome", "dimensions"=>[{:browser=>"Chrome"}], "metrics"=>[{:pageviews=>227}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Chrome&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=Mozilla Compatible Agent", "dimensions"=>[{:browser=>"Mozilla Compatible Agent"}], "metrics"=>[{:pageviews=>60}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Mozilla%20Compatible%20Agent&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=Opera", "dimensions"=>[{:browser=>"Opera"}], "metrics"=>[{:pageviews=>33}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Opera&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=BlackBerry9700", "dimensions"=>[{:browser=>"BlackBerry9700"}], "metrics"=>[{:pageviews=>8}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=BlackBerry9700&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=BlackBerry8900", "dimensions"=>[{:browser=>"BlackBerry8900"}], "metrics"=>[{:pageviews=>7}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=BlackBerry8900&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=Mozilla", "dimensions"=>[{:browser=>"Mozilla"}], "metrics"=>[{:pageviews=>2}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Mozilla&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}, {"title"=>"ga:browser=Camino", "dimensions"=>[{:browser=>"Camino"}], "metrics"=>[{:pageviews=>1}], "id"=>"http://www.google.com/analytics/feeds/data?ids=ga:12316&ga:browser=Camino&start-date=2010-02-27&end-date=2011-02-27", "updated"=>#}]
有沒有一種簡單的方法,使之成爲以壓平:
[2047,1196,835,227,60,33,8,7,2,1]
也
['Internet Explorer','Firefox','Chrome','Mozilla Compatible Agent','Opera','BlackBerry9700','Mozilla','Camino']
這不會很容易閱讀... – BoltClock 2011-02-27 13:29:40
有沒有一種簡單的方法來漂亮打印.inspect? – Tom 2011-02-27 13:40:59
'require'pp';放置your_array.pretty_inspect'或'require'pp'; pp your_array' – 2011-02-27 14:54:21