我需要检查数组是否
a1 = [x, y]
以数组数组的形式呈现,例如
a2 = [ [a, b], [c,d], [e, f] ]
使用 Ruby 1.9。例如, ifx == c和y == dthen 函数必须是True. 我试过了
a2.includes? a1但a1 in a2
两者都不起作用。
看你用过includes?,应该是include?。
a2 = [ [:a, :b], [:c,:d], [:e,:f] ]
a1 = [:a,:b]
p a2.include? a1 #=>true
或者你可以这样做:
a2 = [ [:a, :b], [:c,:d], [:e,:f] ]
a1 = [:a,:b]
p a2.one? { |i| i == a1} #=>true