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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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 = 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
This topic is locked and can not be replied to.