From: avi@...4.com (Avi Bryant) Date: 2002-04-05T07:12:57+09:00 Subject: Re: Is eval a code/design smell? harryo@zip.com.au (Harry Ohlsen) wrote in message news:... > In this particular case, we're not doing a general eval, either, > but a couple of instance_eval calls, to allow the > serialise/deserialise to work with classes that may wish to restrict > access to some of their attributes (for example, if the programmer > wants some attribute to be read-only because it's a derived value, > or for some other reason). > I think it was you who pointed to this being something that perhaps > the language should be providing support for. That would be even > nicer, but isn't there right now, so far as I know. Hmm, I don't think it was me - after all, the language *does* provide support for this. It's called instance_eval. Now, what it doesn't do is provide a nicely named method for it, but that's easy to add: class Object def set_inst_var(name, value) instance_eval "..." end end I dunno exactly what magic you're using inside that instance_eval, so I'll leave that up to you. But my point is, as long as you encapsulate it cleanly, the actual use of eval shouldn't be a code smell to anyone but matz.