From: "David A. Black" Date: 2008-08-09T02:37:04+09:00 Subject: Re: Still missing the boat on class/instance methods Hi -- On Sat, 9 Aug 2008, Frederick Cheung wrote: > > On 8 Aug 2008, at 15:42, Jeff wrote: > >> On Aug 5, 5:30 am, "David A. Black" wrote: >>> ActiveRecord overrides #find for its association collections, so you'd >>> have to use #detect, or a :conditions clause on the find. >> >> It's one of the few things that make me cringe about Rails - some >> native Ruby things are changed when they shouldn't be. >> > > The association proxy isn't an Array, so an association proxy having it's own > find is no different that one of your classes implemeneting a [] method > >> I wonder if I could submit a patch to make #find, when given only a >> block, fall back to "normal" Ruby usage. > > One way out is some_activerecord_object.some_collection.to_a.find Also, #detect is not overridden, so you can do: obj.some_collection.detect {...} David -- Rails training from David A. Black and Ruby Power and Light: * Advancing With Rails August 18-21 Edison, NJ * Co-taught by D.A. Black and Erik Kastner See http://www.rubypal.com for details and updates!