我从我的模型中获取了一些数据(在一个名为results
的变量中),我想根据它们的键将它组织到数组中。 I.E,每个genreName值应该被推入到genres []数组中,每个actorID到cast []数组中。如何根据数字键将数据值排列到数组中 - Ruby
results
:
#<Genre genreName: "Fantasy">
#<Genre genreName: "Comedy">
#<Genre genreName: "Children">
#<Genre genreName: "Animation">
#<Genre genreName: "Adventure">
#<Actor actorID: "tom_hanks", actorName: "Tom Hanks">
#<Actor actorID: "tim_allen", actorName: "Tim Allen">
#<Actor actorID: "don_rickles", actorName: "Don Rickles">
#<Actor actorID: "jim_varney", actorName: "Jim Varney">
#<Actor actorID: "wallace_shawn", actorName: "Wallace Shawn">
#<Director directorID: "john_lasseter", directorName: "John Lasseter">
#<Country countryName: "USA">
#<Location locationName: "N/A">
什么你有什么建议?我正在尝试在Ruby中完成此操作。
编辑
也许会更有意义,所有的对象值添加到哈希,但我担心唯一的密钥名称...
您应该将'results'显示为一个有效的Ruby对象。假设它是一个字符串数组:'results = [“#,...”#“]'。 –
...如果'results'是一组类实例,需要说。 –