ruby-style-guide icon indicating copy to clipboard operation
ruby-style-guide copied to clipboard

A community-driven Ruby coding style guide

Results 75 ruby-style-guide issues
Sort by recently updated
recently updated
newest added

RSpec Expectations allow syntax like: ``` ruby expect { ... some code ... }.to raise_error(MyErrorClass, my_error_message) ``` However if the code under test is not trivially short, it will need...

How should one format multiline boolean expressions? For instance maybe each condition is a long statement and it would be too long or unreadable on a single line. Or should...

The guide doesn't give any specification about file naming in the case of acronyms in the class name. [https://github.com/rubocop-hq/ruby-style-guide#snake-case-for-files](url) Following the logic that each word should be separated by an...

I was a bit surprised with a colleague today when I learned that this was allowed by default: ```ruby def foo numbers = [1,2,3] numbers.map do |n| n+1 end end...

I've always avoided `extend`ing objects at runtime, like in this example: ```ruby class Polymorphic def initialize(style: :foo) extend Something if style == :bar # ... end end ``` It used...

Approved

> Prefer the use of exceptions from the standard library over introducing new exception classes. I feel this is not quite accurate. Indeed, a gem should use standard library exceptions...

Approved

Recently, I came across this: ```ruby do_something if value1 &.!= value2 ``` Which was equal parts very cool and startling. So I wanted to get community feedback on whether or...

### Rationale Breaking control flow is almost certainly the most significant thing that is going on in that line of code, and so it deserves the most prominent spot, at...

The guide advises using `fetch` for hashes. I discovered recently that Array also supports `fetch`, so that attempting to retrieve a non-existing element raises an `IndexError` rather than returning `nil`:...

New Rule

https://github.com/rubocop-hq/ruby-style-guide#no-braces-opts-hash See also https://github.com/rubocop-hq/rubocop/issues/7641 `foo(kw: 1)` and `foo({kw: 1})` will have different meanings in Ruby 3. And Ruby warns them since Ruby 2.7 if it is used unexpectedly, and Ruby...