<div dir="ltr">If you're right your example doesn't show it because you set the local var `foo` to ["b"] before you add ["c"] to it.<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 1, 2014 at 10:52 AM, Ronny Ager-Wick <span dir="ltr"><<a href="mailto:ronny@ager-wick.com" target="_blank">ronny@ager-wick.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>I was just playing around in irb, and
it seems to work... I didn't look into it theoretically, but when
the map and the terrain don't match, I tend to trust the terrain.<div class=""><br>
<br>
irb(main):001:0> def foo<br>
irb(main):002:1> @bar ||= []<br>
irb(main):003:1> end<br></div>
=> nil<br>
irb(main):004:0> def foo= obj<br>
irb(main):005:1> @bar = obj<br>
irb(main):006:1> end<br>
=> nil<br>
irb(main):007:0> foo<br>
=> []<br>
irb(main):008:0> foo + ["a"]<br>
=> ["a"]<br>
irb(main):009:0> foo = ["b"]<br>
=> ["b"]<br>
irb(main):010:0> foo += ["c"]<br>
=> ["b", "c"]<div><div class="h5"><br>
<br>
<br>
On 01/07/14 17:46, Gabe da Silveira wrote:<br>
</div></div></div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr">That will do absolutely nothing since he's not
calling self.foo=<br>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Tue, Jul 1, 2014 at 10:36 AM,
Ronny Ager-Wick <span dir="ltr"><<a href="mailto:ronny@ager-wick.com" target="_blank">ronny@ager-wick.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>You don't have any definition for what should
happen to foo when assigning a value.<br>
Try adding this:<br>
<br>
def foo= obj<br>
@b = obj<br>
end
<div>
<div><br>
<br>
<br>
On 01/07/14 17:12, Kenneth Lee wrote:<br>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div>
<div dir="ltr">
<p>Doing some lazy instantiation and come across
this oddity, maybe I'm just being dense.</p>
<p><font face="courier new, monospace">$ irb</font></p>
<p><font face="courier new, monospace">irb(main):001:0>
def foo</font></p>
<p><font face="courier new, monospace">irb(main):002:1>
@bar ||= []</font></p>
<p><font face="courier new, monospace">irb(main):003:1>
end</font></p>
<p><font face="courier new, monospace">=>
:foo</font></p>
<p><font face="courier new, monospace">irb(main):004:0>
foo</font></p>
<p><font face="courier new, monospace">=> []</font></p>
<p><font face="courier new, monospace">irb(main):005:0>
foo += []</font></p>
<p><font face="courier new, monospace">NoMethodError:
undefined method `+' for nil:NilClass</font></p>
<p><font face="courier new, monospace"><span> </span>from
(irb):5</font></p>
<p><font face="courier new, monospace"><span> </span>from
/Users/ken/.rbenv/versions/2.1.1/bin/irb:11:in
`<main>'</font></p>
<p><font face="courier new, monospace">irb(main):006:0>
foo</font></p>
<p><font face="courier new, monospace">=> nil</font></p>
</div>
<br>
<fieldset></fieldset>
<br>
</div>
</div>
<div>
<pre>_______________________________________________
Chat mailing list
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a>
</pre>
</div>
</blockquote>
<br>
</div>
<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
Chat mailing list
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a>
</pre>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div></div>