On Wed, 04 Jan 2006 21:32:25 -0000, Peter Lacey  
<placey / wanderingbarque.com> wrote:

> On Jan 4, 2006, at 3:47 PM, Phil Tomson wrote:
>
>> I'm not so sure it's faster; it uses a class_eval.
>
> There's a comment in the actual active record code that notes that  
> class_eval is used over define_method to get around a memory leak in  
> fcgi.
>
> But to Ako's point, it seems to me that there has to be some important  
> difference between the singleton approach and the class instance var  
> approach for several reasons:
>
> 1. DHH and the other active record coders and reviewers know what  
> they're doing, and I suspect this seemingly convoluted code wouldn't  
> have survived for very long if it was simply "another way of doing it."
>
> 2.  I'm very new to Ruby, and I don't know what I'm doing. :-)
>
> 3. The active record code _does_ use class instance vars in other  
> places, so this looks very intentional.
>

Seems to me the technique is about one-time creation of attribute  
accessors that, instead of looking like:

	def name
	  "name"
	end

Which, when called multiple times, may be faster than equivalent instance  
variable lookups. My *guess* is that this is probably a bit quicker with  
symbols and maybe strings (which is what this seems to be using - notice  
the 'inspect' too) than going for an instance var.

?

-- 
Ross Bamford - rosco / roscopeco.remove.co.uk