From: Bill Kelly Date: 2005-05-07T13:35:21+09:00 Subject: Re: RCR 303: nil should accept missing methods and return nil From: "John Carter" > > Prove me wrong, take the challenge. > > Next time your pet program dies of a NoMethodError for NilClass add > > class NilClass > def method_missing(sym,*args) > nil > end > end > > ...at the head of your program. > > See empirically what happens. Does it hide bugs? Does it just work? Does > it still throw an exception or give an error message? A CGI script I coded a couple weeks ago just got: [Fri May 06 20:22:37 PDT 2005] Process 27695 encountered # at /var/www/---------.net/www/quake/servers/list.cgi:133:in `top_client' and indeed, when I added method_missing to NilClass the bug was masked and the script executed without complaint. Interesting . . . The bug was something in an as-yet untested "else" case in the code. Something a unit test should have caught, if i'd written any for this quick hack..... which I didn't. I would count myself in the "fail as early as possible" camp. I still don't like that NilClass#method_missing masks the bug... but it did prevent the error in this case from the user's point of view. If I were to consider adding NilClass#method_missing permanently to my script(s), I would at least cause it to write the problem and stack trace to a logfile, so that I could periodically scan the logfile for any such incidents. Interesting challenge though, thanks ... :) Regards, Bill