From: dblack@... Date: 2006-03-04T12:59:25+09:00 Subject: Re: Write up on hazards of instance_eval? Hi -- On Sat, 4 Mar 2006, itsme213 wrote: > Is there any good write up on the hazards of instance_eval? Or do you happen > to have your top-10 on the tip of your fingers? I don't know whether there are ten distinct hazards, but a couple of things to keep in mind: instance_eval gives you more access to an object's state than the object might have planned on. You can change its instance variables and call private methods, for example. Another thing to be careful about is obscurity, caused by things like this: class C def x(&block) @a = 1 instance_eval &block end end @a = 2 C.new.x { puts @a } # 1, where a visual parse might suggest 2 Those are the things that come to mind, along with the usual eval concerns in cases where you're giving instance_eval a string. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black