[LRUG] Ruby question for a change! Why does this happen...

Matthew Rudy Jacobs matthewrudyjacobs at gmail.com
Tue Jul 1 02:18:17 PDT 2014


On 1 July 2014 17:16, Evgeny Shadchnev <evgeny.shadchnev at gmail.com> wrote:

> When you say foo += [], this means foo = foo + []. The first thing that
> Ruby sees is foo on the left hand side. Since it's an assignment, it
> implicitly creates a new local variable foo that's nil by default. When it
> comes to evaluating the right hand side, foo is a reference to this local
> variable, not your method.
>
> I'm not 100% correct that this is exactly what's going on, so please
> correct me if I'm wrong.
>
> Best,
> Evgeny
>
>
I was in the middle of writing the same thing.

And I agree on the reasoning.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140701/1b5a0d83/attachment-0003.html>


More information about the Chat mailing list