From: Kirk Haines Date: 2010-11-10T06:03:58+09:00 Subject: Re: Analyzer for errors in code ? --0016364267351a299c0494a5148c Content-Type: text/plain; charset=ISO-8859-1 On Nov 9, 2010 11:56 AM, "David Unric" wrote: Robert Klemme wrote in post #960353: > On Tue, Nov 9, 2010 at 5:00 PM, David Unric wrote: >> I would like to check ... I understand it is difficult because the dynamic nature of Ruby, but Python is in the same league and PyLint tool does "wonders" at detecting possible errors without code execution (http://www.logilab.org/card/pylintfeatures). It uses Abstract Syntax Tree parser and Ruby also has its own AST so it would be possible. But I asked for something more simplistic, like revealing trivial errors like mentioned variable name typo. See the following example: Running with 'ruby -c' returns 'Syntax OK'. Running with 'ruby -w' also doesn't warn about undefined 'mymsg' variable. Only when the condition becomes true, execution aborts with `
': undefined local variable or method `mymsg' for main:Object (NameError) if __FILE__ == $0 my_msg = 'Hello' if ARGV[0] == 'doit' puts mymsg else puts 'Nope' end end How to avoid such pitfalls with writing more complex ruby code ? I can't believe there is no other way how to verify the code without 'waiting for exception at proper conditions' and then solve the bug. -- Posted via http://www.ruby-forum.com/. --0016364267351a299c0494a5148c--