From: GianFranco Bozzetti Date: 2010-04-09T17:40:13+09:00 Subject: Re: match at least one element of array to another "Kenneth Eunjung" wrote in message news:a0e11eac489f01c9d1d359a71d775b4b@ruby-forum.com... > Hi is there a simple way to return true if at least one element of an > array matches at least one element of another array? > > For example let's say I have @groups = '4,6'.split(',') and @allowed = > '1,4'.split(',') > > I want these to be true because 4 is in both @groups and @allowed. > > Thank you! > -- > Posted via http://www.ruby-forum.com/. > array1 & array2 returns a new_ array with elements common to both arrays. Test on new_array.size returns true if common elements exsist, false if not. @groups = '4,6'.split(',') @allowed = '1,4'.split(',') a = @groups & @allowed # => [4] puts a.inspect.to_s # => [4] ret = (a.size > 0) puts ret.to_s # => true b = [4,6] & [5,7] puts b.inspect.to_s # => [] ret = (b.size > 0) puts ret.to_s # => false exit Hth gfb