On Thu, 14 Nov 2002 06:58:16 +0900, 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".

Well, I'm not sure that I'd agree tht it's "evil", but it is most
certainly "ugly." (I consider most eval situations "ugly", including
one that I'll probably have to do because I can't find a way other
than "eval" to "compile" a string into a proc.)

It would still be useful to yield-with-context so that I can use
either protected or private methods within a block; something like:

  instance_yield args if block_given?

> 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 actually completely agree with Joel's point. The only reason that
Text::Format doesn't use your method is I didn't think of it (:

-austin
-- Austin Ziegler, austin / halostatue.ca on 2002.11.13 at 18.18.20