Lyle Johnson wrote:
 > Austin Ziegler wrote:
 >
 >> On Thu, 14 Nov 2002 05:10:40 +0900, Joel VanderWerf wrote:
 >>
 >>> Either way, you're breaking encapsulation--by exposing writers, or
 >>> by exposing the attrs themselves at the time of construction
 >>> (only).
 >>
 >>
 >> You're right, and in some cases, that's OK (see Text::Format for
 >> this; I haven't yet modified it to use Lyle's change -- I may not),
 >> since all of the methods are exposed anyway.
 >
 >
 > The original implementation (introduced in FXRuby 1.0.14) used
 > instance_eval to evaluate the initialization block. I changed it in
 > FXRuby 1.0.15 to instead yield 'self' to the block, primarily because
 > (as Rich Kilmer so eloquently noted "instance_eval() is evil".
 >
 > I sort-of agree with Joel's point that either approach breaks
 > encapsulation, assuming that the class' public interface doesn't already
 > provide writers for the attributes of interest. But I think of the two,
 > using instance_eval to explicitly open-up instance variables is
 > definitely more brittle. Remember, an instance method that is a "plain
 > old" attr_writer today could be replaced in the future by a different
 > implementation that does something different (i.e. touches different
 > instance variables or whatever).

I agree completely. There's also the point that using yield rather than
instance_eval lets you refer to attributes in the static scope:

@last_name = "powers"

me = Person.new {
    @name = 'austin' + @last_name
    @age = 31
}

With instance_eval, you have to pass @last_name into the block using a
local var.