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

Given these declarations:

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

You can do this:

c = {|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 }


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs