Skip to content

Add improvements to styleguide #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract method-related rules into own section
  • Loading branch information
elenatanasoiu committed Aug 28, 2022
commit fe295a73dd0fb14964fd54daef78f3d29127522b
42 changes: 26 additions & 16 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ This is GitHub's Ruby Style Guide, inspired by [RuboCop's guide][rubocop-guide].
12. [Regular Expressions](#regular-expressions)
13. [Requires](#requires)
14. [Strings](#strings)
15. [Syntax](#syntax)
15. [Methods](#methods)
1. [Method definitions](#method-definitions)
2. [Method calls](#method-calls)

16. [Syntax](#syntax)

## Layout

Expand Down Expand Up @@ -558,7 +562,9 @@ paragraphs.each do |paragraph|
end
```

## Syntax
## Methods

### Method definitions

* Use `def` with parentheses when there are arguments. Omit the
parentheses when the method doesn't accept any arguments.
Expand All @@ -573,6 +579,24 @@ end
end
```

### Method calls

* If the first argument to a method begins with an open parenthesis,
always use parentheses in the method invocation. For example, write
`f((3 + 2) + 1)`.

* Never put a space between a method name and the opening parenthesis.

``` ruby
# bad
f (3 + 2) + 1

# good
f(3 + 2) + 1
```

## Syntax

* Never use `for`, unless you know exactly why. Most of the time iterators
should be used instead. `for` is implemented in terms of `each` (so
you're adding a level of indirection), but with a twist - `for`
Expand Down Expand Up @@ -779,20 +803,6 @@ enabled = true if enabled.nil?
one-liner scripts is discouraged. Prefer long form versions such as
`$PROGRAM_NAME`.

* Never put a space between a method name and the opening parenthesis.

``` ruby
# bad
f (3 + 2) + 1

# good
f(3 + 2) + 1
```

* If the first argument to a method begins with an open parenthesis,
always use parentheses in the method invocation. For example, write
`f((3 + 2) + 1)`.

* Use `_` for unused block parameters.

``` ruby
Expand Down