Question: I use following now to check syntax error:

```
system "ruby -wc path/to/file.rb"

```

but it very waste time if there are too many file(for instance, i refactory code), so **my question is:** is there way to ruby syntax check in ruby code?

Answer: 
Under MRI, you can use `RubyVM::InstructionSequence#compile` ([relevant documentation](http://ruby-doc.org/core-2.2.0/RubyVM/InstructionSequence.html#method-c-compile)) to compile Ruby code (which will throw exceptions if there are errors):

```
2.1.0 :001 > RubyVM::InstructionSequence.compile "a = 1 + 2"
 => <RubyVM::InstructionSequence:<compiled>@<compiled>>

2.1.0 :002 > RubyVM::InstructionSequence.compile "a = 1 + "
<compiled>:1: syntax error, unexpected end-of-input
a = 1 +
        ^
SyntaxError: compile error
        from (irb):2:in `compile'
        from (irb):2
        from /usr/local/rvm/rubies/ruby-2.1.0/bin/irb:11:in `<main>'

```
You can use Ripper, the Ruby interface to the Ruby parser:

<http://ruby-doc.org/stdlib/libdoc/ripper/rdoc/Ripper.html>