From: Jamey Cribbs Date: 2006-07-22T04:44:19+09:00 Subject: Re: [ANN] Mongoose 0.2.0 John W. Long wrote: > Jamey Cribbs wrote: >> Plane.find do |plane| >> plane.speed > 350 >> plane.any do >> plane.country == 'USA' plane.country == 'Great Britain' >> end >> end >> >> Now, looks like this: >> >> Plane.find do >> speed > 350 >> any do >> country == 'USA' >> country == 'Great Britain' >> end >> end > > James, could you elaborate on how this is done? I would assume that > the first method is better because you don't lose the the surrounding > scope. What's going on in that do block? Actually, I like the second way better, because you don't have to clutter up your query with lots of references to your table class. The way it works is that in the Plane.find method, I grab the block and pass it to #instance_eval. This executes the block in the Plane classes environment, so it knows that when it sees the attribute "speed" or "country" in the block, it knows to call Plane.speed and Plane.country. Planes.speed happens to be a reference to a SkiplistColumn instance and it knows how to handle the "> 350" passed to it. I have to credit Ezra for pointing me to this. The reference to "any" just calls Plane.any which is a method in the Plane class that knows how to take the block inside of it and format it as a sub-query of the main query. Jamey Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.