Re: Is there an "in" operator in ruby?


#1

Given these declarations:

a = [*1…10]
b = [2,4,6,8]

You can do this:

c = a.select {|i| b.include?(i) }
c.each {|i| puts i}

Or this:

a.each {|i| puts i if b.include?(i) }

Or this:

(a & b).each {|i| puts i }

Steve