Ruby/ RoR - 针对关联数组循环对象数组
我有一个问题 @questions 对象数组
---
- !ruby/object:Question
attributes:
id: "1"
answer: "2"
- !ruby/object:Question
attributes:
id: "7"
answer: "1"
- !ruby/object:Question
attributes:
id: "6"
answer: "4"
- !ruby/object:Question
attributes:
id: "4"
answer: "1"
和一个答案数组 @answers
--- !map:ActiveSupport::HashWithIndifferentAccess
"1": "2"
"7": "3"
"6": "4"
"4": "0"
我如何使用任何循环机制验证问题的答案?
在上面的示例中,只有第一个问题的答案是正确的,我需要将其作为数组输出,如下所示
--- !map:ActiveSupport::HashWithIndifferentAccess
"1": true
"7": false
"6": false
"4": false
I h've an array of object of Questions @questions
---
- !ruby/object:Question
attributes:
id: "1"
answer: "2"
- !ruby/object:Question
attributes:
id: "7"
answer: "1"
- !ruby/object:Question
attributes:
id: "6"
answer: "4"
- !ruby/object:Question
attributes:
id: "4"
answer: "1"
And an Array of Answers @answers
--- !map:ActiveSupport::HashWithIndifferentAccess
"1": "2"
"7": "3"
"6": "4"
"4": "0"
How can i validate Answers against Questions with any loop mechanism?
In the above example only the answer for the first question is correct, i need to get out put as an array like one below
--- !map:ActiveSupport::HashWithIndifferentAccess
"1": true
"7": false
"6": false
"4": false
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)