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

Runable · August 06, 2018 · Last by robertyu replied at August 06, 2018 · 1188 hits

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

.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 Floor has deleted

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

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

You need to Sign in before reply, if you don't have an account, please Sign up first.