first
options = args.last || {}
find_without_rquery(amount, options.merge(:conditions =>
conditions.to_find_conditions))
else
find_without_rquery(*args)
end
end
alias_method :find_without_rquery, :find
alias_method :find, :find_with_rquery
end
end
Now we know that if there is no block passed in, we obviously don??™t want to be using our
new block syntax, so we forward them to the original version, and everyone is happy. But what??™s
that new RQuery::Conditions object? And what??™s it doing? You caught me, I jumped forward
a bit. We need an object to actually do the work for us, and we do need to call the original find
method in the end. Like I said, it does a lot of stuff already, so we shouldn??™t go messing around
with something that??™s already working if we don??™t need to.
Meet method_missing
The RQuery::Conditions class is what actually runs the block we??™ve passed into find that contains
the comparisons, but it can??™t run the block as it is; it needs to know a few things beforehand.
First, what??™s the cow object that gets passed in? And how does it turn comparisons into SQL?
Well, to answer that, you need to know something about Ruby method calling.
Pages:
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272