Ever felt the inertia when you shift from a programming language, which you have been using for quite a few years, to a completely new one? You have, haven't you? While that inertia is a broad topic, I'll be talking about a small part of it today, which is following the community guidelines for coding.
From what I have seen so far, Ruby has a gem of a community and it's not surprising that they have a gem for you to learn writing Ruby code in the community-accepted way.
Introducing, RuboCop, a static code analyzer for Ruby which not only enforces community guidelines for coding but also fixes some of the problems for you. As Officer Alex J. Murphy said, all role models are important and so is this. Now let's how we can install this gem in our project. Add this line in your Gemfile and run bundle install
gem 'rubocop', require: false
That's it, now you can check all the files in your project with this command
$ rubocop
You can also configure rubocop as per your liking, just create a file .rubocop.yml in the root of your project. Here's how you can include or exclude files
AllCops:
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'db/**/*'
- 'config/**/*'
- 'script/**/*'
- !ruby/regexp /old_and_unused\.rb$/
Now you're all set to write better Ruby code. Happy coding!
From what I have seen so far, Ruby has a gem of a community and it's not surprising that they have a gem for you to learn writing Ruby code in the community-accepted way.
Introducing, RuboCop, a static code analyzer for Ruby which not only enforces community guidelines for coding but also fixes some of the problems for you. As Officer Alex J. Murphy said, all role models are important and so is this. Now let's how we can install this gem in our project. Add this line in your Gemfile and run bundle install
gem 'rubocop', require: false
That's it, now you can check all the files in your project with this command
$ rubocop
You can also configure rubocop as per your liking, just create a file .rubocop.yml in the root of your project. Here's how you can include or exclude files
AllCops:
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'db/**/*'
- 'config/**/*'
- 'script/**/*'
- !ruby/regexp /old_and_unused\.rb$/
Now you're all set to write better Ruby code. Happy coding!
No comments:
Post a Comment