I want to pull a list of terms and use them to scan documents to
determine if any of those words are present.

Let's say fruits = ["apples","oranges","grapes"].

I do Regexp.union(*fruits).  This returns /apples|oranges|grapes/ which
is good.

Now I want this pattern to be case insensitive, i.e. -
/apples|oranges|grapes/i

Docs say I can set each argument to case insensitive and then call union
e.g. - Regexp.union(/dogs/, /cats/i)        #=>
/(?-mix:dogs)|(?i-mx:cats)/


I have been doing fruits.map!{|fruit| Regexp.new(fruit,
Regexp::IGNORECASE)}; Regexp.union(*fruits)

This seems to work.  Is there any better or cleaner way to do this?

Thanks,

John
-- 
Posted via http://www.ruby-forum.com/.