所以,如果我有一个像这样的哈希数组:(ruby初学者)
input = [ {"last_name"=>"Gay","first_name"=>"Rudy","display_name"=>"Rudy Gay","position"=>"SF","minutes"=>39,"points"=>25,"assists"=>6},{"last_name"=>"Collison","first_name"=>"Darren","display_name"=>"Darren Collison","position"=>"PG","points"=>14,"assists"=>4} ]
我将如何遍历数组以及迭代每个哈希以得到类似这样的东西:
player1 = {display_name =>“rudy gay”,“position”=>“SF”}
player2 = {display_name =>“darren collison”,“position”=>“PG”}
它会是什么样的
input.each do |x| Player.create(name: x['display_name'],position: x['position'] end
有没有更好的方法来实现这一目标?
谢谢!