嘿,我正在尝试将此对象转换为一个整数数组,例如阵列(3,4,6)
- - !ruby/object:Code
attributes:
candidate_id: "3"
attributes_cache: {}
- !ruby/object:Code
attributes:
candidate_id: "4"
attributes_cache: {}
- !ruby/object:Code
attributes:
candidate_id: "6"
attributes_cache: {}
这是我试过的东西
result = @intersection.map{|c| c.candidate_id}
由于
答案 0 :(得分:1)
尝试以下方法:
或强>
我不熟悉YAML,但您可能想尝试使用哈希而不是代码对象。另外,如果你确实使用了代码类,你应该确保你拥有和attr_accessor(然后你的旧代码应该可以工作)。