Skip to content

Commit bb48cf3

Browse files
meagarMatthew Eagar
authored andcommitted
[Fix rubocop#223] Cover use of {} in argument hash
Explicitly cover whether {} should be used around options hashes being passed to methods
1 parent 65b172e commit bb48cf3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,29 @@ Never use `::` for regular method invocation.
723723
bowling.score.should == 0
724724
```
725725
726+
* Omit the outer braces around an implicit options hash.
727+
728+
```Ruby
729+
# bad
730+
user.set({ name: 'John', age: 45, permissions: { read: true } })
731+
732+
# good
733+
User.set(name: 'John', age: 45, permissions: { read: true })
734+
```
735+
736+
* Omit both the outer braces and parentheses for methods that are
737+
part of an internal DSL.
738+
739+
```Ruby
740+
class Person < ActiveRecord::Base
741+
# bad
742+
validates(:name, { presence: true, length: { within: 1..10 } })
743+
744+
# good
745+
validates :name, presence: true, length: { within: 1..10 }
746+
end
747+
```
748+
726749
* Omit parentheses for method calls with no arguments.
727750
728751
```Ruby

0 commit comments

Comments
 (0)