From: Robert Klemme Date: 2004-05-13T18:48:55+09:00 Subject: Re: How to make combinations of an array to produce all possible expressions? "Erik Terpstra" schrieb im Newsbeitrag news:40a333fc$0$65124$e4fe514c@news.xs4all.nl... > I have an array 'conds', which contains some sub-expressions for an > xpath query: > > conds = ["@title='Foo'", "@edition='Bar'", "@date='20040513'"] > > Is there an existing library that lets me construct all possible > combinations like this? > > puts conds..collect{|n| n.join ' and '} > > which produces: > > @title='Foo' and @edition='Bar' and @date='20040513' > @title='Foo' and @edition='Bar' > @title='Foo' and @date='20040513' > @edition='Bar' and @date='20040513' > @title='Foo' > @edition='Bar' > @date='20040513' Not yet, but: module Enumerable def combine masks = inject([[], 1]){|(ar, m), e| [ar< puts conds.combine.collect{|n| n.join ' and '} @title='Foo' @edition='Bar' @title='Foo' and @edition='Bar' @date='20040513' @title='Foo' and @date='20040513' @edition='Bar' and @date='20040513' @title='Foo' and @edition='Bar' and @date='20040513' => nil robert