From: Sean O'Halpin Date: 2007-11-08T16:39:48+09:00 Subject: Re: Dynamic syntax check On Nov 8, 2007 5:01 AM, aemadrid@gmail.com wrote: > Is there any way to check the Ruby syntax on a file or string of Ruby > code besides doing something like `ruby -v xyz.rb`? Is there a gem > that would help me here? > > Thanks in advance, > > > Adrian Madrid > > This should give you a starting point: def eval_with_check(str, b = binding) begin eval(str, b) "OK" rescue SyntaxError => e "ERROR: #{e}" end end puts eval_with_check("1+2") puts eval_with_check("this is not valid") puts eval_with_check("RUBY_VERSION") You could also look into LoadError and other runtime exceptions (don't remember off the top of my head). Regards, Sean