From: sera@... (Francis Hwang) Date: 2004-05-28T22:00:47+09:00 Subject: Re: defining condititions Guillaume Marcais wrote in message news:<1085504342.29598.2.camel@comp>... > Kansas, written by Kirk Haines, has such a conditions system to write > SQL queries. You may want to check it out: > > http://enigo.com/projects/kansas/index.html > > Guillaume. Other examples to check out would include: - Criteria, for querying databases and other data stores: http://mephle.org/Criteria/ - Lafcadio, an O-R mapping layer for MySQL: http://lafcadio.rubyforge.org/ - Runt, for defining time-based rulesets for defining calendars without explicitly choosing dates: http://runt.rubyforge.org/ Probably this sort of thing is easier if you have an object that's explicitly the receiver of the various methods. So instead of what you'd originally asked: my_set.rules = !name("orange") && hasProperty("color") && (hasProperty("size") || hasProperty("weight")) It might be easier to define something that looks like: my_set.createRules { |set| set.name('orange').not & set.hasProperty('color') & ( set.hasProperty('size') | set.hasProperty('weight') } Inside the block, the variable "set" is actually a special object that pretends to be a set but really has funny methods defined to create the various Rule primitives you've already defined. This is how I implemented it in Lafcadio and it's worked well so far. One other note: Beyond the fact that you can't override && and ||, you also cannot override unary negation, so you get no control over what !name('orange') means. That's why in the example code I wrote it calls set.name('orange').not instead ... if you make it a method you can do whatever's necessary. Francis