我希望从散列中删除nil有价值的键.article是存储每篇文章的类,并且attributes方法将文章存储为散列.
预期结果:
{"articles":[{"results":[{"author":null,"title":"Former bar manager jailed for preying on homeless 14-year-old girl","summary":"<p><img src=\"http://images.theage.com.au/2015/08/24/6790912/Thumbnail999662740gisd08image.related.thumbnail.320x214.gj68pg.png1440386418031.jpg-90x60.jpg\" width=\"90\" height=\"60\" style=\"float:left;margin:4px;border:0px\"/></p>A man who preyed on a 14-year-old girl he came across living on the streets of Wodonga has been jailed for nine months.","images":null,"source":null,"date":"Mon, 24 Aug 2015 03:20:21 +0000","guid":"<guid isPermaLink=\"false\">gj68pg</guid>","link":"http://www.theage.com.au/victoria/former-bar-manager-jailed-for-preying-on-homeless-14yearold-girl-20150824-gj68pg.html","section":null,"item_type":null,"updated_date":null,"created_date":null,"material_type_facet":null,"abstract":null,"byline":null,"kicker":null}]}]}
Run Code Online (Sandbox Code Playgroud)
希望从上面的输出中删除空值.
def attributes
hash = {
"author" => @author,
"title" => @title,
"summary" => @summary,
"images" => @images,
"source" => @source,
"date" => @date
}
hash = {}
count = 0 …Run Code Online (Sandbox Code Playgroud)