From: Rolando Abarca Date: 2007-12-15T03:19:22+09:00 Subject: Re: simple way to turn "foo and bar" to "+foo +bar" On Dec 14, 2007, at 2:48 PM, Max Williams wrote: > I want to add a slightly hacky feature into my boolean mysql search > which lets users write 'foo and bar', which is then translated into > '+foo +bar' (ie both 'foo' and 'bar' must be present) before being > passed to the search. Similarly, "foo and bar and snafu" should be > translated into "+foo +bar +snafu". > > I'm sure there must be a simple way to do this but i'm new to ruby and > have got bogged down in loads of nested ifs and exceptions already. > > Can anyone help with an elegant solution? "foo and bar and baz".split(/\s+and\s+/i).map{|s| "+#{s}"}.join(' ') > thanks > max regards, -- Rolando Abarca Phone: +56-9 97851962 My Amazon Wish List: http://www.amazon.com/gp/registry/wishlist/3AGJOT5E6SIQB