Rails 请问如何在匹配一个数字在一个数字数组中存在

Runable · 2018年08月06日 · 最后由 robertyu 回复于 2018年08月06日 · 1187 次阅读

请问如何在匹配一个数字在一个数字数组中存在,或者说一个数组怎么判断包含另外一个数组

.4.1 :001 > a=[1,2,3,4,5]
 => [1, 2, 3, 4, 5] 
2.4.1 :002 > b=3
 => 3 
2.4.1 :003 > a.includes? b
NoMethodError: undefined method `includes?' for [1, 2, 3, 4, 5]:Array
Did you mean?  include?
        from (irb):3
2.4.1 :004 > a.include? b
 => true 
2.4.1 :005 > b.in? a
 => true 

2 楼 已删除

感谢,很有用,问题解决了

a=[1,2,3,4] b=[2,3,4] b - a == []

需要 登录 后方可回复, 如果你还没有账号请 注册新账号