ruby-style-guide
ruby-style-guide copied to clipboard
A community-driven Ruby coding style guide
I encountered a situation where a `do...end` block syntax is used as a work-around to avoid line limits. **Example:** ``` # frozen_string_literal: true if [].any? do |variable| # do something...
This suggestion concerns [this](https://github.com/bbatsov/ruby-style-guide#fail-method). The style guide gives good reasons to use `fail`, but I think that for abstract interfaces `raise NotImplementedError`should be preferred way and mentioned on the style...
Should assignment in conditional ternary be avoided ? something like this ``` condition ? self.foo = bar : self.foo2 = bar2 ``` it's dealing with operator precedence and it is...
Reading https://thoughtbot.com/blog/ruby-safe-navigation reminded me that over-use of `&.` is common. I think it would be helpful to add a guideline such as: > Avoid long chains of `&.`. Replace with...
Many users forget to call `super` from `initialize`, which can lead to tricky bugs if the superclass needs to initialize its own state. Perhaps this should be in the style...
Based on discussion: https://github.com/rubocop-hq/rubocop/pull/7325/files#r320964544 Rubocop issue: https://github.com/rubocop-hq/rubocop/issues/7299
At https://github.com/rubocop/ruby-style-guide#suppressing-exceptions, it says "Don't suppress" exceptions, but then lists `do_something rescue nil` as a good example. ``` # good do_something rescue nil ``` It could be my ignorance, but...
Following my [PR introducing a cop for numbered parameters](https://github.com/rubocop/rubocop/pull/10100), @koic [suggested](https://github.com/rubocop/rubocop/pull/10100#issuecomment-923011088) that choosing the default style required a discussion in the style guide. As a basis, here is what we...
Reference: rubocop/rubocop#8327 and rubocop/rubocop#10082 The follow pairs have equivalent behaviour: ```ruby array.select { |x| x.match?(REGEXP) } array.grep(REGEXP) array.reject { |x| x.match?(REGEXP) } array.grep_v(REGEXP) ``` Previous to ruby 3, `grep`/`grep_v` had...
`extend self` and `module_function` are not the same. The guide says: > Favor the use of module_function over extend self when you want to turn a module's instance methods into...