From: 7stud -- Date: 2009-08-23T20:12:01+09:00 Subject: Re: [array & regexp] Development - works, production not - w Joao Silva wrote: > > This may be ruby bug? > Nope. $ ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.11.1] $ ri Regexp.union ---------------------------------------------------------- Regexp::union Regexp.union([pattern]*) => new_str ------------------------------------------------------------------------ Return a +Regexp+ object that is the union of the given _pattern_s, i.e., will match any of its parts. The _pattern_s can be Regexp objects, in which case their options will be preserved, or Strings. If no arguments are given, returns +/(?!)/+. Regexp.union #=> /(?!)/ Regexp.union("penzance") #=> /penzance/ Regexp.union("skiing", "sledding") #=> /skiing|sledding/ Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/ ------------------------ arr = [/term/, /term2/, /termx/] puts Regexp.union(*arr) --output:-- (?-mix:(?-mix:term)|(?-mix:term2)|(?-mix:termx)) You should also be able to use that code in ruby 1.8.7 if Regexp.union has the same definition in ruby 1.9: $ri19 Regexp.union ---------------------------------------------------------- Regexp::union Regexp.union(pat1, pat2, ...) => new_regexp Regexp.union(pats_ary) => new_regexp From Ruby 1.9.1 ------------------------------------------------------------------------ Return a +Regexp+ object that is the union of the given _pattern_s, i.e., will match any of its parts. The _pattern_s can be Regexp objects, in which case their options will be preserved, or Strings. If no patterns are given, returns +/(?!)/+. Regexp.union #=> /(?!)/ Regexp.union("penzance") #=> /penzance/ Regexp.union("a+b*c") #=> /a+b*c/ Regexp.union("skiing", "sledding") #=> /skiing|sledding/ Regexp.union(["skiing", "sledding"]) #=> /skiing|sledding/ Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/ -- Posted via http://www.ruby-forum.com/.