<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 3 Aug 2011, at 12:05, Matthew Rudy Jacobs wrote:</div><br><blockquote type="cite"><div>

I didn't think "case()" was defined</div><div>but my guess is that it means "case nil"</div><div><br></div><div>so effectively you're saying;</div><div><br></div><div>"when nil is @question"?</div>

<div>and in the case it fails</div><div>its because @question is exactly nil.</div><div><br></div></blockquote><div><br></div><div>This isn't right - irb exploration shows that case with no comparison value is *not* equivalent to case nil.</div><div><br></div><div><div>ruby-1.9.2-p290 :001 > class SomeClass</div><div>ruby-1.9.2-p290 :002?>   def page_description</div><div>ruby-1.9.2-p290 :003?>     description = case</div><div>ruby-1.9.2-p290 :004 >         when @question then @question.background</div><div>ruby-1.9.2-p290 :005?>       else "Something"</div><div>ruby-1.9.2-p290 :006?>       end</div><div>ruby-1.9.2-p290 :007?>     description</div><div>ruby-1.9.2-p290 :008?>     end</div><div>ruby-1.9.2-p290 :009?>   end</div><div> => nil </div><div>ruby-1.9.2-p290 :010 > class Question</div><div>ruby-1.9.2-p290 :011?>   attr_accessor :background</div><div>ruby-1.9.2-p290 :012?>   end</div><div> => nil </div><div>ruby-1.9.2-p290 :013 > class SomeClass</div><div>ruby-1.9.2-p290 :014?>   attr_writer :question</div><div>ruby-1.9.2-p290 :015?>   end</div><div> => nil </div><div>ruby-1.9.2-p290 :016 > some_obj = SomeClass.new</div><div> => #<SomeClass:0x000001010ced90> </div><div>ruby-1.9.2-p290 :017 > some_obj.page_description</div><div> => "Something" </div><div>ruby-1.9.2-p290 :018 > some_obj.question = nil</div><div> => nil </div><div>ruby-1.9.2-p290 :019 > some_obj.page_description</div><div> => "Something" </div><div>ruby-1.9.2-p290 :020 > class SomeClass</div><div>ruby-1.9.2-p290 :021?>   def page_description</div><div>ruby-1.9.2-p290 :022?>     description = case nil</div><div>ruby-1.9.2-p290 :023?>       when @question then @question.background</div><div>ruby-1.9.2-p290 :024?>       else "Something"</div><div>ruby-1.9.2-p290 :025?>       end</div><div>ruby-1.9.2-p290 :026?>     description</div><div>ruby-1.9.2-p290 :027?>     end</div><div>ruby-1.9.2-p290 :028?>   end</div><div> => nil </div><div>ruby-1.9.2-p290 :029 > some_obj = SomeClass.new</div><div> => #<SomeClass:0x00000100940240> </div><div>ruby-1.9.2-p290 :030 > some_obj.page_description</div><div>NoMethodError: undefined method `background' for nil:NilClass</div><div>        from (irb):23:in `page_description'</div><div>        from (irb):30</div><div>        from /Users/Tom/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'</div><div><br></div><div>See page 141 of the pickaxe for this use of case.</div><div><br></div><div>Cheers,</div><div><br></div><div>Tom</div></div><br><blockquote type="cite"><div><br><div class="gmail_quote">On 3 August 2011 11:57, Simon Coffey <span dir="ltr"><<a href="mailto:simon@tribesports.com">simon@tribesports.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi LRUG,<br>
<br>
Apologies for posting a bug to the list, but it's weird enough that I<br>
hope it might be interesting (indeed it appears to be logically<br>
impossible). It's got me completely stumped, so any thoughts would be<br>
gratefully received.<br>
<br>
We're getting very occasional (~1 per week) exceptions out of one of<br>
our helper methods in our app (Rails 3.0.3, ruby 1.9.2-p180). For<br>
example, from the following line of code...<br>
<br>
 def page_description<br>
   case<br>
   when @question then @question.background            # exception raised here<br>
   <snip other cases><br>
   end<br>
 end<br>
<br>
... we saw "NoMethodError: undefined method `background' for<br>
nil:NilClass". (The full method can be seen here:<br>
<a href="https://gist.github.com/1120170" target="_blank">https://gist.github.com/1120170</a> )<br>
<br>
That's logically impossible, right? @question is clearly nil, as shown<br>
by the exception. But @question is also clearly not nil, otherwise how<br>
on earth would that case fire?<br>
<br>
Other rules in this case statement are also causing exceptions, but<br>
with inexplicable things apparently stored in the instance variables.<br>
For example, we've seen "NoMethodError: undefined method `bio' for<br>
#<Lead:0xdbc31a0>" from line #6 in the gist, despite the @user<br>
instance variable only ever being assigned an instance of User, not<br>
Lead. Another time @user appeared to contain a Hash. Other instance<br>
variables have contained controller instances.<br>
<br>
This only seems to be happening in the #page_description method, which<br>
is used at the top of the <head> section of our layouts. As such, for<br>
any given render pass it will always be the first call to access the<br>
controller instance variables.<br>
<br>
It looks to me like our instance variables are somehow getting<br>
corrupted, but I can't for the life of me see how this would happen.<br>
Unfortunately it happens only on production, and has so far resisted<br>
being reproduced, so we have no ability to get further info out of the<br>
debugger.<br>
<br>
Has anyone seen anything like this before? Undying gratitude / a beer<br>
to anyone who has any bright ideas...<br>
<br>
Cheers,<br>
Simon<br>
<br>
--<br>
Simon Coffey<br>
Developer, Tribesports<br>
<br>
e: <a href="mailto:simon@tribesports.com">simon@tribesports.com</a><br>
m: 07960 004 857<br>
p: Unit 104, Cremer Business Centre, 37 Cremer Street, London, E2 8HD<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">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>
</blockquote></div><br></div>
_______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>http://lists.lrug.org/listinfo.cgi/chat-lrug.org<br></blockquote></div><br></body></html>