0
检查我需要检查,如果阵列阵列包含用Ruby
a1 = [x, y]
在数组的数组呈现像
a2 = [ [a, b], [c,d], [e, f] ]
使用Ruby 1.9。 例如,如果x == c
和y == d
那么函数必须是True
。 I'v已尝试
a2.includes? a1
和a1 in a2
但这两个都没有工作。
检查我需要检查,如果阵列阵列包含用Ruby
a1 = [x, y]
在数组的数组呈现像
a2 = [ [a, b], [c,d], [e, f] ]
使用Ruby 1.9。 例如,如果x == c
和y == d
那么函数必须是True
。 I'v已尝试
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
哦,我的坏!感谢您的纠正,对于Ruby来说还是新的 – user2296537
请问'a2.any? {| x | x.eql? a1}'做什么? –
是的,我刚刚检查过,它也可以工作,还有'include?'' – user2296537
我一直在[Ruby Doc]中保存'Array'和'Enumerable'的文档(http://www.ruby-doc.org/core -2.0/Array.html)在我的浏览器中,当我编码时。这是一个非常宝贵的来源。 –