Ruby array includes? pattern
Friday, June 1, 2012
Array#include? with pattern match
To check if a pattern exists in an array
class Array ## takes a pattern as argument and return the ## first index the pattern matched to the element in the array def i_rgx(pattern) j=-1 self.each_with_index {|e,i| j=i;break if(e.match(pattern))} j end end
Home
Subscribe to:
Posts (Atom)