From: Robert Klemme Date: 2010-11-25T21:37:31+09:00 Subject: Re: instance_eval vs attr_reader On Thu, Nov 25, 2010 at 1:07 PM, Joe Pikachu wrote: > Hi, I'm new in forum; even newer in programming. > I would like to know what is faster (uses less memory) to retrieve data? > I use ruby 1.8 series. > > my_class.instance_eval(@var) or > my_class.var #using attr_reader I guess "my_class" is meant to be an instance and not necessarily a class. Btw, there's also #instance_variable_get and #instance_variable_set. > My question is based on the fact one have to asign a symbol to use the > 'attr_reader' type thus creating 'memory leaks', while not in the > former. But I'm not sure. If you're concerned with performance you can easily measure it (see module Benchmark) and can work with hard facts. However, this would almost certainly be a micro optimization and since we know that "premature optimization is the root of all evil" I would first use the proper approach (i.e. define accessors). Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/