[LRUG] Ruby question for a change! Why does this happen...
Kenneth Lee
kenfodder at gmail.com
Tue Jul 1 02:21:35 PDT 2014
Yep, that explains it, concat might be a cleaner method to use for what
that was doing. Code refactored, many thanks!
On 1 July 2014 10:18, Matthew Rudy Jacobs <matthewrudyjacobs at gmail.com>
wrote:
> 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/b3c109d7/attachment-0003.html>
More information about the Chat
mailing list