如何在数组中迭代这个数组以查看所有值是否相等?

时间:2013-10-04 02:27:46

标签: ruby arrays each

这是我的示例代码

:key1 => "a"
:key2 => "b"
:key3 => "c"
array1 = [[:key1, :key1, :key1],[:key1, :key2, :key3],[:key2, :key2, :key1]]
array1.each { |x| if x.sym_tos == "a"
                     puts "All match!"
                  else
                     puts "no match"
                  end
             }

然而,当我运行它时,我收到以下错误代码: 用于[:R1C1,:R1C2,:R1C3]的未定义方法`sym_to_s':数组(NoMethodError)

1 个答案:

答案 0 :(得分:2)

你可能想说

if x.uniq.length == 1