<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">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>
@bar = obj<br>
end<br>
<br>
<br>
On 01/07/14 17:12, Kenneth Lee wrote:<br>
</div>
<blockquote
cite="mid:CANr5rXsAmpYPCxEZ0rw2eJGj3ipCmGNq785GHQEq_=4mPpQXsA@mail.gmail.com"
type="cite">
<div dir="ltr">
<p class="">Doing some lazy instantiation and come across this
oddity, maybe I'm just being dense.</p>
<p class=""><font face="courier new, monospace">$ irb</font></p>
<p class=""><font face="courier new, monospace">irb(main):001:0>
def foo</font></p>
<p class=""><font face="courier new, monospace">irb(main):002:1>
@bar ||= []</font></p>
<p class=""><font face="courier new, monospace">irb(main):003:1>
end</font></p>
<p class=""><font face="courier new, monospace">=> :foo</font></p>
<p class=""><font face="courier new, monospace">irb(main):004:0>
foo</font></p>
<p class=""><font face="courier new, monospace">=> []</font></p>
<p class=""><font face="courier new, monospace">irb(main):005:0>
foo += []</font></p>
<p class=""><font face="courier new, monospace">NoMethodError:
undefined method `+' for nil:NilClass</font></p>
<p class=""><font face="courier new, monospace"><span class="">
</span>from (irb):5</font></p>
<p class=""><font face="courier new, monospace"><span class="">
</span>from /Users/ken/.rbenv/versions/2.1.1/bin/irb:11:in
`<main>'</font></p>
<p class=""><font face="courier new, monospace">irb(main):006:0>
foo</font></p>
<p class=""><font face="courier new, monospace">=> nil</font></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Chat mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a>
<a class="moz-txt-link-freetext" href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a>
</pre>
</blockquote>
<br>
</body>
</html>