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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Molitor, Stephen L (Guest)
on 2006-04-19 21:04
(Received via mailing list)
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 topic is locked and can not be replied to.