From: Robert Klemme Date: 2011-04-04T18:13:15+09:00 Subject: Re: Using grep on subarrays - help! On Sun, Apr 3, 2011 at 4:44 PM, Adam Prescott wrote: > 2011/4/3 Jesús Gabriel y Galán > >> result = [] >> test.each {|x| result << x unless x.grep(/one/).empty?} >> result >> > > More to-the-point: > > test.reject { |x| x.grep(/one/).empty? } It seems we may want to match at the first position only, so I'd rather do one of those irb(main):003:0> test.select {|a,b| /one/ =~ a} => [["one", "vol1"], ["one", "vol2"]] irb(main):004:0> test.select {|a,b| a == "one"} => [["one", "vol1"], ["one", "vol2"]] If we are only interested in the other bit irb(main):005:0> test.select {|a,b| a == "one"}.map {|a,b| b} => ["vol1", "vol2"] Or, with #inject for a change since we know the key when doing exact matches irb(main):006:0> test.inject([]) {|r,(a,b)| a == "one" ? r << b : r} => ["vol1", "vol2"] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/