From: Pit Capitain Date: 2005-12-08T01:11:39+09:00 Subject: Re: Syntax checker? William E. Rubin schrieb: > Ruby doesn't seem to check for class names, function names, and so > forth until it actually hits a line that tries to use such a thing. Is > there a way to get it to check up front, without having to run the > script through every possible line of code? > > I understand that this is not strictly "syntax" checking, and that Ruby > does actually do a "syntax" check. So I mean some other term, more > along the lines of what a traditional compiler will do (minus the > actual compilation). Hi William, if you call the ruby interpreter with the -c command line option, then it performs a syntax check: C:\tmp>ruby -c r.rb Syntax OK (http://www.ruby-doc.org/docs/ProgrammingRuby/html/rubyworld.html#UA) On the other hand, if you want to syntactically check for valid class names, then you're out of luck. Ruby is too dynamic. Look at this little script: C:\tmp>type r.rb print "enter class name: " name = gets.chomp Object.const_set name, Class.new p X.new This script prompts the user for a classname and then creates a new class under that name. It then tries to create an instance of class X. You can't check whether "X" is a valid class name without actually running the code: C:\tmp>ruby r.rb enter class name: X # C:\tmp>ruby r.rb enter class name: Y C:/tmp/r.rb:5: uninitialized constant X (NameError) I'm not sure the Ruby IDEs can give you more hints about misspelled names. The best way for me is simply doing Test Driven Development. Regards, Pit