James Edward Gray II wrote:
> On Nov 19, 2005, at 3:47 PM, Todd wrote:
>
> > OK, maybe I'm going about it the wrong way.  I specified it wrong in
> > the original post anyway.  What I want to do is have the block be able
> > to modify the variables in the method that's yielding to it.
> >
> > Like:
> >
> > def foo
> >   a = 1
> >   yield
> >   #block does something with a, such that this a is now a new value,
> > say add 1
> >   a
> > end
> >
> > foo { #some code here }
> >
> > => 2
>
> Use block parameters for this:
>
>  >> def foo
>  >>   a = 1
>  >>   a = yield a
>  >>   p a
>  >> end
> => nil
>  >> foo do |var| var + 1 end
> 2
> => nil

This is in fact how I'm doing it now, but I guess I was trying to avoid
having to do:

a = yield a

since this will be a large iteration and I'm worried the GC won't keep
up.

> It can be tricky, inheriting from Ruby's core classes and thus is
> probably better avoided.  Favor composition over inheritance.
>

Yeah, I suppose have some pondering to do.

> James Edward Gray II

Thanks again,
Todd