我正在使用散列在Ruby中的散列,名为MYMOVIES
,如下所示。现在散列哈希,如何获得第一个嵌套散列的键
{"127 Hours"=>
{"title"=>"127 Hours",
"year"=>"2010",
"plays"=>1,
"last_played"=>1300489200,
"seen_date"=>"19/3/2011",
"imdb_id"=>"tt1542344",
"rating"=>"6",
"omdbapiurl"=>"http://www.omdbapi.com/?t=127 Hours&y=2010"},
"Zombieland"=>
{"title"=>"Zombieland",
"year"=>"2009",
"plays"=>1,
"last_played"=>1290207600,
"seen_date"=>"20/11/2010",
"imdb_id"=>"tt1156398",
"rating"=>"7",
"omdbapiurl"=>"http://www.omdbapi.com/?t=Zombieland&y=2009"}}
,我想获得第一嵌套哈希的所有键(即名称,年份,播放,...,omdbapiurl)。
我试着用:
mynestedhash = MYMOVIES.first
puts mynestedhash.keys.to_s
但我得到的错误:
undefined method `keys' for #<Array:0x801c56f8> (NoMethodError)
我怎么能这样做?
太好了,非常感谢! – MDT