On Tue, Apr 26, 2011 at 4:55 PM, Peter Szinek <peter.szinek / gmail.com> wrote:

> def foo(bar)
> #DO SOMETHING with bar here resulting in baz being set to {}
> end
>
> baz = {:fluff => :ork}
> foo(baz)
> #baz should be {} now
>
> I'd like to use it in a code which calls a callback, (the foo method in
> this case) but the callback is called from multiple places, and only
> inside foo() we know whether we want to empty the array or not... it
> would be complicated to return something from foo() with the current
> architecture (based on which we could empty the hash or not).

You cannot change the reference stored in the caller's baz, because
Ruby has pass by value semantics. But hashes are mutable, in
particular

    baz.clear

wipes the hash, so the caller will see it empty as well.