seebs
7/4/2007 12:30:00 AM
In message <c6c1a0550707031707h1acf4ad8m6758b9c400f128c3@mail.gmail.com>, "Matt Greer" writes:
>And so I take it with blocks, they are given a new reference to the objects
>in question and therefore assigning to the variables in the block has no
>effect on the method. ie
Right.
>def around_string(string, &block)
> b = nil
> a = nil
> yield(b,a)
> "#{b}#{string}#{a}"
>end
>
>around_string('center') { |b, a| b = 'left'; a = 'right' }
>
>is worthless because in the block I'm merely assigning objects to local
>references that go out of scope once the block exits?
Exactly. The block's return in this case is just the string 'right' (the last
expression in the block).
You could easily do
a, b = yield
and call with
{ 'left', 'right' }
-s