-2

Is there a way to check ruby code to prevent 'NoMethodError' or 'NameError'?

I tried some gems: rubocop, reek, roodi. Useful tools for ruby best practices but not for my need.

I use vim so a cli tool will be welcome.

Thanks

BroiSatse
  • 44,031
  • 8
  • 61
  • 86
AVVD
  • 19
  • 3
  • 1
    In ruby methods can be defined during the execution, so there is no way to tell whether given method will be defined at the time it is called. In some cases, the method is never defined, but it relies on method_missing to handle it. This is one of the many reasons why you should always write tests. – BroiSatse Oct 23 '14 at 09:37
  • I saw that RubyMine can 'detect' this type of error 'on-the-fly' and they says the inspection feature is based on the tools I mentioned. I saw the way of using method_missing to handle this exception but it needs to run the program. – AVVD Oct 23 '14 at 09:48
  • 1
    this is what I am saying here - there is no way to tell without running the code. Best way to run the code is to have well written test suite with high code coverage. – BroiSatse Oct 23 '14 at 09:49
  • 1
    It doesn't answer your question, but the `did_you_mean` gem is pretty nifty when handling such errors http://www.yukinishijima.net/2014/10/21/did-you-mean-experience-in-ruby.html – tessi Oct 23 '14 at 11:55

1 Answers1

1

I found what I want :) : ruby-lint

https://rubygems.org/gems/ruby-lint/

https://github.com/YorickPeterse/ruby-lint

Analysis Classes:

  * argument_amount
  * pedantics
  * shadowing_variables
  * undefined_methods
  * undefined_variables
  * unused_variables
  * useless_equality_checks

I search for "ruby static code checker"

Thank you for your help

AVVD
  • 19
  • 3